<!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>[204693] 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/204693">204693</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-08-21 06:36:48 -0700 (Sun, 21 Aug 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>cross-origin requests redirected fail or drop author requested headers
https://bugs.webkit.org/show_bug.cgi?id=112471
Patch by Youenn Fablet <youenn@apple.com> on 2016-08-21
Reviewed by Alex Christensen.
Source/WebCore:
Test: http/tests/xmlhttprequest/redirections-and-user-headers.html
Storing original headers in DocumentThreadableLoader.
In case of cross-origin redirection in CORS mode, set the new request headers to the original headers.
Add a special handling to Authorization header that should not be used when it is already removed by the network layer.
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::redirectReceived):
(WebCore::DocumentThreadableLoader::loadRequest):
* loader/DocumentThreadableLoader.h:
LayoutTests:
* http/tests/xmlhttprequest/redirections-and-user-headers-expected.txt: Added.
* http/tests/xmlhttprequest/redirections-and-user-headers.html: Added.
* http/tests/xmlhttprequest/resources/access-control-preflight-redirect.php: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentThreadableLoadercpp">trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentThreadableLoaderh">trunk/Source/WebCore/loader/DocumentThreadableLoader.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsxmlhttprequestredirectionsanduserheadersexpectedtxt">trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsxmlhttprequestredirectionsanduserheadershtml">trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers.html</a></li>
<li><a href="#trunkLayoutTestshttptestsxmlhttprequestresourcesaccesscontrolpreflightredirectphp">trunk/LayoutTests/http/tests/xmlhttprequest/resources/access-control-preflight-redirect.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (204692 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-08-21 12:18:43 UTC (rev 204692)
+++ trunk/LayoutTests/ChangeLog        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-08-21 Youenn Fablet <youenn@apple.com>
+
+ cross-origin requests redirected fail or drop author requested headers
+ https://bugs.webkit.org/show_bug.cgi?id=112471
+
+ Reviewed by Alex Christensen.
+
+ * http/tests/xmlhttprequest/redirections-and-user-headers-expected.txt: Added.
+ * http/tests/xmlhttprequest/redirections-and-user-headers.html: Added.
+ * http/tests/xmlhttprequest/resources/access-control-preflight-redirect.php: Added.
+
</ins><span class="cx"> 2016-08-19 Sam Weinig <sam@webkit.org>
</span><span class="cx">
</span><span class="cx"> Location.ancestorOrigins should return a FrozenArray<USVString>
</span></span></pre></div>
<a id="trunkLayoutTestshttptestsxmlhttprequestredirectionsanduserheadersexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers-expected.txt (0 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers-expected.txt         (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers-expected.txt        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php?redirect=true&url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-preflight-redirect.php. Cross-origin redirection denied by Cross-Origin Resource Sharing policy.
+CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php?redirect=true&url=http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php. Cross-origin redirection denied by Cross-Origin Resource Sharing policy.
+
+PASS Check headers after same-origin redirection to same-origin resource (simple request)
+PASS Check headers after same-origin redirection to same-origin resource (not simple request)
+PASS Check headers after same origin redirection to cross-origin resource (simple request)
+PASS Check headers after same origin redirection to cross-origin resource (not simple request)
+PASS Check headers after cross-origin redirection to same-origin resource (simple request)
+FAIL Check headers after cross-origin redirection to same-origin resource (not simple request) promise_test: Unhandled rejection with value: "Loading failure"
+PASS Check headers after cross-origin redirection to cross-origin resource (simple request)
+FAIL Check headers after cross-origin redirection to cross-origin resource (not simple request) promise_test: Unhandled rejection with value: "Loading failure"
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsxmlhttprequestredirectionsanduserheadershtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers.html (0 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers.html         (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/redirections-and-user-headers.html        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -0,0 +1,91 @@
</span><ins>+<!DOCTYPE html>
+<html>
+ <head>
+ <title>XMLHttpRequest: ensure user script headers do not get dropped during cross-origin redirections</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ </head>
+ <body>
+ <script type="text/javascript">
+function doTest(testName, testURL, simpleRequest, changeOrigin)
+{
+ promise_test(function(test) {
+ var resolvePromise, rejectPromise;
+ var promise = new Promise((resolve, reject) => {
+ resolvePromise = resolve;
+ rejectPromise = reject;
+ });
+
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", testURL);
+ xhr.setRequestHeader("accept", "groovy");
+
+ if (!simpleRequest) {
+ xhr.setRequestHeader("x-webkit", "funky");
+ xhr.setRequestHeader("content-type", "rocky");
+ xhr.setRequestHeader("authorization", "Basic QXV0aG9yaXphdGlvbi1IZWFkZXI6QXV0aG9yaXphdGlvbi1IZWFkZXI=");
+ }
+
+ xhr.onload = (test) => {
+ assert_true(xhr.responseText.indexOf("accept header found: groovy") !== -1, "xhr final request should have an accept=groovy header");
+ if (!simpleRequest) {
+ assert_true(xhr.responseText.indexOf("x-webkit header found: funky") !== -1, "xhr final request should have a x-webkit=funky header");
+ assert_true(xhr.responseText.indexOf("content-type header found: rocky") !== -1, "xhr final request should have a content-type=groovy header");
+ assert_true(xhr.responseText.indexOf("not found any authorization header") !== -1, "xhr final request should not have an authorization header");
+ }
+ testPassed = true;
+ }
+
+ xhr.onerror = (e) => {
+ rejectPromise("Loading failure");
+ }
+
+ var testPassed = false;
+ xhr.onloadend = () => {
+ testPassed ? resolvePromise() : rejectPromise("testPassed is not true");
+ }
+ xhr.send();
+ return promise;
+ }, testName);
+}
+
+var simpleRequest = true;
+
+doTest("Check headers after same-origin redirection to same-origin resource (simple request)",
+ "resources/access-control-preflight-redirect.php?redirect=true&url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ simpleRequest);
+
+doTest("Check headers after same-origin redirection to same-origin resource (not simple request)",
+ "resources/access-control-preflight-redirect.php?redirect=true&url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ !simpleRequest);
+
+doTest("Check headers after same origin redirection to cross-origin resource (simple request)",
+ "resources/access-control-preflight-redirect.php?redirect=true&url=http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ simpleRequest);
+
+doTest("Check headers after same origin redirection to cross-origin resource (not simple request)",
+ "resources/access-control-preflight-redirect.php?redirect=true&url=http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ !simpleRequest);
+
+doTest("Check headers after cross-origin redirection to same-origin resource (simple request)",
+ "http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php?redirect=true&url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ simpleRequest);
+
+// FIXME: Thistest will not pass as long as not-simple cross origin requests are not allowed to redirect. See https://bugs.webkit.org/show_bug.cgi?id=159056.
+doTest("Check headers after cross-origin redirection to same-origin resource (not simple request)",
+ "http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php?redirect=true&url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ !simpleRequest);
+
+doTest("Check headers after cross-origin redirection to cross-origin resource (simple request)",
+ "http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php?redirect=true&url=http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ simpleRequest);
+
+// FIXME: Thistest will not pass as long as not-simple cross origin requests are not allowed to redirect. See https://bugs.webkit.org/show_bug.cgi?id=159056.
+doTest("Check headers after cross-origin redirection to cross-origin resource (not simple request)",
+ "http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php?redirect=true&url=http://localhost:8080/xmlhttprequest/resources/access-control-preflight-redirect.php",
+ !simpleRequest);
+
+ </script>
+ </body>
+</html>
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsxmlhttprequestresourcesaccesscontrolpreflightredirectphp"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/xmlhttprequest/resources/access-control-preflight-redirect.php (0 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/xmlhttprequest/resources/access-control-preflight-redirect.php         (rev 0)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/resources/access-control-preflight-redirect.php        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -0,0 +1,47 @@
</span><ins>+<?php
+
+header("Access-Control-Allow-Origin: *");
+header("Access-Control-Allow-Methods: GET");
+header("Access-Control-Allow-Headers: authorization, x-webkit, content-type");
+
+if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
+ header("HTTP/1.1 200");
+ return;
+}
+
+$redirect = $_GET['redirect'];
+$url = $_GET['url'];
+
+if (isset($redirect)) {
+ header("HTTP/1.1 302");
+ header("Location: $url");
+ return;
+}
+
+header("HTTP/1.1 200");
+
+if (!isset($_SERVER["HTTP_X_WEBKIT"])) {
+ echo "not found any x-webkit header found";
+} else {
+ echo "x-webkit header found: " . $_SERVER["HTTP_X_WEBKIT"];
+}
+echo "\n";
+if (!isset($_SERVER["HTTP_ACCEPT"])) {
+ echo "not found any accept header found";
+} else {
+ echo "accept header found: " . $_SERVER["HTTP_ACCEPT"];
+}
+echo "\n";
+if (!isset($_SERVER["CONTENT_TYPE"])) {
+ echo "not found any content-type header";
+} else {
+ echo "content-type header found: " . $_SERVER["CONTENT_TYPE"];
+}
+echo "\n";
+if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ echo "not found any authorization header";
+} else {
+ echo "authorization header found";
+}
+
+?>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (204692 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-08-21 12:18:43 UTC (rev 204692)
+++ trunk/Source/WebCore/ChangeLog        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-08-21 Youenn Fablet <youenn@apple.com>
+
+ cross-origin requests redirected fail or drop author requested headers
+ https://bugs.webkit.org/show_bug.cgi?id=112471
+
+ Reviewed by Alex Christensen.
+
+ Test: http/tests/xmlhttprequest/redirections-and-user-headers.html
+
+ Storing original headers in DocumentThreadableLoader.
+ In case of cross-origin redirection in CORS mode, set the new request headers to the original headers.
+ Add a special handling to Authorization header that should not be used when it is already removed by the network layer.
+
+ * loader/DocumentThreadableLoader.cpp:
+ (WebCore::DocumentThreadableLoader::redirectReceived):
+ (WebCore::DocumentThreadableLoader::loadRequest):
+ * loader/DocumentThreadableLoader.h:
+
</ins><span class="cx"> 2016-08-21 Frederic Wang <fwang@igalia.com>
</span><span class="cx">
</span><span class="cx"> Introduce a MathMLAnnotationElement class for the annotation/annotation-xml elements
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentThreadableLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp (204692 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp        2016-08-21 12:18:43 UTC (rev 204692)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -99,6 +99,12 @@
</span><span class="cx">
</span><span class="cx"> m_options.allowCredentials = (m_options.credentials == FetchOptions::Credentials::Include || (m_options.credentials == FetchOptions::Credentials::SameOrigin && m_sameOriginRequest)) ? AllowStoredCredentials : DoNotAllowStoredCredentials;
</span><span class="cx">
</span><ins>+ ASSERT(!request.httpHeaderFields().contains(HTTPHeaderName::Origin));
+
+ // Copy headers if we need to replay the request after a redirection.
+ if (m_async && m_options.mode == FetchOptions::Mode::Cors)
+ m_originalHeaders = request.httpHeaderFields();
+
</ins><span class="cx"> if (m_sameOriginRequest || m_options.mode == FetchOptions::Mode::NoCors) {
</span><span class="cx"> loadRequest(WTFMove(request), DoSecurityCheck);
</span><span class="cx"> return;
</span><span class="lines">@@ -246,9 +252,13 @@
</span><span class="cx">
</span><span class="cx"> clearResource();
</span><span class="cx">
</span><del>- // We need to clean the request again as SubresourceLoader may not always do the cleaning,
- // especially in the case of a cross-origin load but redirection sticking to the same origin.
- cleanRedirectedRequestForAccessControl(request);
</del><ins>+ ASSERT(m_originalHeaders);
+ // Let's fetch the request with the original headers (equivalent to request cloning specified by fetch algorithm).
+ // Do not copy the Authorization header if removed by the network layer.
+ if (!request.httpHeaderFields().contains(HTTPHeaderName::Authorization))
+ m_originalHeaders->remove(HTTPHeaderName::Authorization);
+ request.setHTTPHeaderFields(*m_originalHeaders);
+
</ins><span class="cx"> makeCrossOriginAccessRequest(ResourceRequest(request));
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentThreadableLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.h (204692 => 204693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentThreadableLoader.h        2016-08-21 12:18:43 UTC (rev 204692)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.h        2016-08-21 13:36:48 UTC (rev 204693)
</span><span class="lines">@@ -117,6 +117,7 @@
</span><span class="cx"> bool m_async;
</span><span class="cx"> std::unique_ptr<ContentSecurityPolicy> m_contentSecurityPolicy;
</span><span class="cx"> Optional<CrossOriginPreflightChecker> m_preflightChecker;
</span><ins>+ Optional<HTTPHeaderMap> m_originalHeaders;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>
</body>
</html>