<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[246238] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/246238">246238</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2019-06-09 04:55:29 -0700 (Sun, 09 Jun 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add wildcard to Access-Control-Allow-Methods and Access-Control-Allow-Headers
https://bugs.webkit.org/show_bug.cgi?id=165508

Patch by Rob Buis <rbuis@igalia.com> on 2019-06-09
Reviewed by Frédéric Wang.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt:
* web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt:

Source/WebCore:

According to the spec [1] step 6.5, a wildcard for method
and request's credentials mode should be taken into account, so
add this to the check. Same for Access-Control-Allow-Headers (step 6.7).

[1] https://fetch.spec.whatwg.org/#cors-preflight-fetch

Tests: web-platform-tests/fetch/api/cors/cors-preflight-star.any.html
       web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker.html

* loader/CrossOriginAccessControl.cpp:
(WebCore::validatePreflightResponse):
* loader/CrossOriginPreflightResultCache.cpp:
(WebCore::CrossOriginPreflightResultCacheItem::allowsCrossOriginMethod const):
(WebCore::CrossOriginPreflightResultCacheItem::allowsCrossOriginHeaders const):
(WebCore::CrossOriginPreflightResultCacheItem::allowsRequest const):
* loader/CrossOriginPreflightResultCache.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapicorscorspreflightstaranyexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsfetchapicorscorspreflightstaranyworkerexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloaderCrossOriginAccessControlcpp">trunk/Source/WebCore/loader/CrossOriginAccessControl.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderCrossOriginPreflightResultCachecpp">trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderCrossOriginPreflightResultCacheh">trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2019-06-09  Rob Buis  <rbuis@igalia.com>
+
+        Add wildcard to Access-Control-Allow-Methods and Access-Control-Allow-Headers
+        https://bugs.webkit.org/show_bug.cgi?id=165508
+
+        Reviewed by Frédéric Wang.
+
+        * web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt:
+        * web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt:
+
</ins><span class="cx"> 2019-06-07  Joonghun Park  <jh718.park@samsung.com>
</span><span class="cx"> 
</span><span class="cx">         Implement tab-size with units
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapicorscorspreflightstaranyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt    2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any-expected.txt       2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -1,8 +1,4 @@
</span><del>-CONSOLE MESSAGE: Method SUPER is not allowed by Access-Control-Allow-Methods.
-CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8800/fetch/api/resources/preflight.py?allow_methods=*&allow_headers=x-test& due to access control checks.
</del><span class="cx"> CONSOLE MESSAGE: Method OK is not allowed by Access-Control-Allow-Methods.
</span><del>-CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8800/fetch/api/resources/preflight.py?allow_methods=*&allow_headers=*& due to access control checks.
-CONSOLE MESSAGE: Method OK is not allowed by Access-Control-Allow-Methods.
</del><span class="cx"> CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8800/fetch/api/resources/preflight.py?origin=http://localhost:8800&credentials&allow_methods=*&allow_headers=*& due to access control checks.
</span><span class="cx"> CONSOLE MESSAGE: Method PUT is not allowed by Access-Control-Allow-Methods.
</span><span class="cx"> CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8800/fetch/api/resources/preflight.py?origin=http://localhost:8800&credentials&allow_methods=*&allow_headers=& due to access control checks.
</span><span class="lines">@@ -14,8 +10,8 @@
</span><span class="cx"> CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8800/fetch/api/resources/preflight.py?origin=http://localhost:8800&credentials&allow_methods=put&allow_headers=*& due to access control checks.
</span><span class="cx"> 
</span><span class="cx"> PASS CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test) 
</span><del>-FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Method SUPER is not allowed by Access-Control-Allow-Methods."
-FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Method OK is not allowed by Access-Control-Allow-Methods."
</del><ins>+PASS CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) 
+PASS CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) 
</ins><span class="cx"> PASS CORS that fails with credentials: true; method: OK (allowed: *); header: X-Test,1 (allowed: *) 
</span><span class="cx"> PASS CORS that fails with credentials: true; method: PUT (allowed: *); header:  (allowed: ) 
</span><span class="cx"> PASS CORS that succeeds with credentials: true; method: PUT (allowed: PUT); header:  (allowed: *) 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsfetchapicorscorspreflightstaranyworkerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt     2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker-expected.txt        2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -1,6 +1,4 @@
</span><del>-CONSOLE MESSAGE: Method SUPER is not allowed by Access-Control-Allow-Methods.
</del><span class="cx"> CONSOLE MESSAGE: Method OK is not allowed by Access-Control-Allow-Methods.
</span><del>-CONSOLE MESSAGE: Method OK is not allowed by Access-Control-Allow-Methods.
</del><span class="cx"> CONSOLE MESSAGE: Method PUT is not allowed by Access-Control-Allow-Methods.
</span><span class="cx"> CONSOLE MESSAGE: Request header field X-Test is not allowed by Access-Control-Allow-Headers.
</span><span class="cx"> CONSOLE MESSAGE: Request header field X-Test is not allowed by Access-Control-Allow-Headers.
</span><span class="lines">@@ -7,8 +5,8 @@
</span><span class="cx"> CONSOLE MESSAGE: Method PUT is not allowed by Access-Control-Allow-Methods.
</span><span class="cx"> 
</span><span class="cx"> PASS CORS that succeeds with credentials: false; method: GET (allowed: get); header: X-Test,1 (allowed: x-test) 
</span><del>-FAIL CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) promise_test: Unhandled rejection with value: object "TypeError: Method SUPER is not allowed by Access-Control-Allow-Methods."
-FAIL CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) promise_test: Unhandled rejection with value: object "TypeError: Method OK is not allowed by Access-Control-Allow-Methods."
</del><ins>+PASS CORS that succeeds with credentials: false; method: SUPER (allowed: *); header: X-Test,1 (allowed: x-test) 
+PASS CORS that succeeds with credentials: false; method: OK (allowed: *); header: X-Test,1 (allowed: *) 
</ins><span class="cx"> PASS CORS that fails with credentials: true; method: OK (allowed: *); header: X-Test,1 (allowed: *) 
</span><span class="cx"> PASS CORS that fails with credentials: true; method: PUT (allowed: *); header:  (allowed: ) 
</span><span class="cx"> PASS CORS that succeeds with credentials: true; method: PUT (allowed: PUT); header:  (allowed: *) 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/Source/WebCore/ChangeLog      2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2019-06-09  Rob Buis  <rbuis@igalia.com>
+
+        Add wildcard to Access-Control-Allow-Methods and Access-Control-Allow-Headers
+        https://bugs.webkit.org/show_bug.cgi?id=165508
+
+        Reviewed by Frédéric Wang.
+
+        According to the spec [1] step 6.5, a wildcard for method
+        and request's credentials mode should be taken into account, so
+        add this to the check. Same for Access-Control-Allow-Headers (step 6.7).
+
+        [1] https://fetch.spec.whatwg.org/#cors-preflight-fetch
+
+        Tests: web-platform-tests/fetch/api/cors/cors-preflight-star.any.html
+               web-platform-tests/fetch/api/cors/cors-preflight-star.any.worker.html
+
+        * loader/CrossOriginAccessControl.cpp:
+        (WebCore::validatePreflightResponse):
+        * loader/CrossOriginPreflightResultCache.cpp:
+        (WebCore::CrossOriginPreflightResultCacheItem::allowsCrossOriginMethod const):
+        (WebCore::CrossOriginPreflightResultCacheItem::allowsCrossOriginHeaders const):
+        (WebCore::CrossOriginPreflightResultCacheItem::allowsRequest const):
+        * loader/CrossOriginPreflightResultCache.h:
+
</ins><span class="cx"> 2019-06-08  Zalan Bujtas  <zalan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [LFC][IFC] Introduce Baseline to LineBox
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderCrossOriginAccessControlcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/CrossOriginAccessControl.cpp (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/CrossOriginAccessControl.cpp 2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/Source/WebCore/loader/CrossOriginAccessControl.cpp    2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -207,8 +207,8 @@
</span><span class="cx"> 
</span><span class="cx">     auto result = std::make_unique<CrossOriginPreflightResultCacheItem>(storedCredentialsPolicy);
</span><span class="cx">     if (!result->parse(response)
</span><del>-        || !result->allowsCrossOriginMethod(request.httpMethod(), errorDescription)
-        || !result->allowsCrossOriginHeaders(request.httpHeaderFields(), errorDescription)) {
</del><ins>+        || !result->allowsCrossOriginMethod(request.httpMethod(), storedCredentialsPolicy, errorDescription)
+        || !result->allowsCrossOriginHeaders(request.httpHeaderFields(), storedCredentialsPolicy, errorDescription)) {
</ins><span class="cx">         return false;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderCrossOriginPreflightResultCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.cpp (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.cpp  2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.cpp     2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -68,9 +68,9 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool CrossOriginPreflightResultCacheItem::allowsCrossOriginMethod(const String& method, String& errorDescription) const
</del><ins>+bool CrossOriginPreflightResultCacheItem::allowsCrossOriginMethod(const String& method, StoredCredentialsPolicy storedCredentialsPolicy, String& errorDescription) const
</ins><span class="cx"> {
</span><del>-    if (m_methods.contains(method) || isOnAccessControlSimpleRequestMethodWhitelist(method))
</del><ins>+    if (m_methods.contains(method) || (m_methods.contains("*") && storedCredentialsPolicy != StoredCredentialsPolicy::Use) || isOnAccessControlSimpleRequestMethodWhitelist(method))
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><span class="cx">     errorDescription = "Method " + method + " is not allowed by Access-Control-Allow-Methods.";
</span><span class="lines">@@ -77,12 +77,13 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool CrossOriginPreflightResultCacheItem::allowsCrossOriginHeaders(const HTTPHeaderMap& requestHeaders, String& errorDescription) const
</del><ins>+bool CrossOriginPreflightResultCacheItem::allowsCrossOriginHeaders(const HTTPHeaderMap& requestHeaders, StoredCredentialsPolicy storedCredentialsPolicy, String& errorDescription) const
</ins><span class="cx"> {
</span><ins>+    bool validWildcard = m_headers.contains("*") && storedCredentialsPolicy != StoredCredentialsPolicy::Use;
</ins><span class="cx">     for (const auto& header : requestHeaders) {
</span><span class="cx">         if (header.keyAsHTTPHeaderName && isCrossOriginSafeRequestHeader(header.keyAsHTTPHeaderName.value(), header.value))
</span><span class="cx">             continue;
</span><del>-        if (!m_headers.contains(header.key)) {
</del><ins>+        if (!m_headers.contains(header.key) && !validWildcard) {
</ins><span class="cx">             errorDescription = "Request header field " + header.key + " is not allowed by Access-Control-Allow-Headers.";
</span><span class="cx">             return false;
</span><span class="cx">         }
</span><span class="lines">@@ -97,9 +98,9 @@
</span><span class="cx">         return false;
</span><span class="cx">     if (storedCredentialsPolicy == StoredCredentialsPolicy::Use && m_storedCredentialsPolicy == StoredCredentialsPolicy::DoNotUse)
</span><span class="cx">         return false;
</span><del>-    if (!allowsCrossOriginMethod(method, ignoredExplanation))
</del><ins>+    if (!allowsCrossOriginMethod(method, storedCredentialsPolicy, ignoredExplanation))
</ins><span class="cx">         return false;
</span><del>-    if (!allowsCrossOriginHeaders(requestHeaders, ignoredExplanation))
</del><ins>+    if (!allowsCrossOriginHeaders(requestHeaders, storedCredentialsPolicy, ignoredExplanation))
</ins><span class="cx">         return false;
</span><span class="cx">     return true;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderCrossOriginPreflightResultCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.h (246237 => 246238)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.h    2019-06-09 07:09:48 UTC (rev 246237)
+++ trunk/Source/WebCore/loader/CrossOriginPreflightResultCache.h       2019-06-09 11:55:29 UTC (rev 246238)
</span><span class="lines">@@ -46,8 +46,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT bool parse(const ResourceResponse&);
</span><del>-    WEBCORE_EXPORT bool allowsCrossOriginMethod(const String&, String& errorDescription) const;
-    WEBCORE_EXPORT bool allowsCrossOriginHeaders(const HTTPHeaderMap&, String& errorDescription) const;
</del><ins>+    WEBCORE_EXPORT bool allowsCrossOriginMethod(const String&, StoredCredentialsPolicy, String& errorDescription) const;
+    WEBCORE_EXPORT bool allowsCrossOriginHeaders(const HTTPHeaderMap&, StoredCredentialsPolicy, String& errorDescription) const;
</ins><span class="cx">     bool allowsRequest(StoredCredentialsPolicy, const String& method, const HTTPHeaderMap& requestHeaders) const;
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre>
</div>
</div>

</body>
</html>