Title: [190418] trunk
Revision
190418
Author
an...@apple.com
Date
2015-10-01 11:09:07 -0700 (Thu, 01 Oct 2015)

Log Message

Network cache: Subresource referer header wrong after cached redirect
https://bugs.webkit.org/show_bug.cgi?id=149709
rdar://problem/22917174

Reviewed by Chris Dumez.

Source/WebKit2:

If a main resource is loaded from a cache entry that involved redirects the document
will end up setting the Referer-headers of the subresources to the request URL not the redirected URL

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::didRetrieveCacheEntry):

    If a cache entry involved a redirect synthesize a minimal willSendRequest message so that WebCore side
    runs through the same code paths as when receiving a redirect from network.

LayoutTests:

* http/tests/cache/redirect-referer-expected.html: Added.
* http/tests/cache/redirect-referer.html: Added.
* http/tests/cache/resources/load-and-check-referer.php: Added.
* http/tests/cache/resources/permanent-redirect.php: Added.
* http/tests/cache/resources/redirect-referer-iframe.html: Added.
* http/tests/cache/resources/redirect-referer-iframe-expected.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (190417 => 190418)


--- trunk/LayoutTests/ChangeLog	2015-10-01 17:45:59 UTC (rev 190417)
+++ trunk/LayoutTests/ChangeLog	2015-10-01 18:09:07 UTC (rev 190418)
@@ -1,3 +1,18 @@
+2015-10-01  Antti Koivisto  <an...@apple.com>
+
+        Network cache: Subresource referer header wrong after cached redirect
+        https://bugs.webkit.org/show_bug.cgi?id=149709
+        rdar://problem/22917174
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/cache/redirect-referer-expected.html: Added.
+        * http/tests/cache/redirect-referer.html: Added.
+        * http/tests/cache/resources/load-and-check-referer.php: Added.
+        * http/tests/cache/resources/permanent-redirect.php: Added.
+        * http/tests/cache/resources/redirect-referer-iframe.html: Added.
+        * http/tests/cache/resources/redirect-referer-iframe-expected.html: Added.
+
 2015-10-01  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         accessibility/mac/aria-expanded-notifications.html is flaky

Added: trunk/LayoutTests/http/tests/cache/redirect-referer-expected.html (0 => 190418)


--- trunk/LayoutTests/http/tests/cache/redirect-referer-expected.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/redirect-referer-expected.html	2015-10-01 18:09:07 UTC (rev 190418)
@@ -0,0 +1,2 @@
+<iframe src=""
+<iframe src=""

Added: trunk/LayoutTests/http/tests/cache/redirect-referer.html (0 => 190418)


--- trunk/LayoutTests/http/tests/cache/redirect-referer.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/redirect-referer.html	2015-10-01 18:09:07 UTC (rev 190418)
@@ -0,0 +1,17 @@
+<body>
+<script>
+var rnd = Math.floor(Math.random() * 1000000000000000);
+var iframeSrc = "resources/permanent-redirect.php?location=redirect-referer-iframe.html&rnd=" + rnd;
+
+var iframe = document.createElement("iframe");
+iframe.src = ""
+iframe._onload_ = function () {
+    if (window.internals)
+        internals.clearMemoryCache();
+    var iframe = document.createElement("iframe");
+    iframe.src = ""
+    document.body.appendChild(iframe);
+}
+document.body.appendChild(iframe);
+
+</script>

Added: trunk/LayoutTests/http/tests/cache/resources/load-and-check-referer.php (0 => 190418)


--- trunk/LayoutTests/http/tests/cache/resources/load-and-check-referer.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/resources/load-and-check-referer.php	2015-10-01 18:09:07 UTC (rev 190418)
@@ -0,0 +1,40 @@
+<?
+function contentType($path)
+{
+    if (preg_match("/\.html$/", $path))
+        return "text/html";
+    if (preg_match("/\.manifest$/", $path))
+        return "text/cache-manifest";
+    if (preg_match("/\.js$/", $path))
+        return "text/_javascript_";
+    if (preg_match("/\.xml$/", $path))
+        return "application/xml";
+    if (preg_match("/\.xhtml$/", $path))
+        return "application/xhtml+xml";
+    if (preg_match("/\.svg$/", $path))
+        return "application/svg+xml";
+    if (preg_match("/\.xsl$/", $path))
+        return "application/xslt+xml";
+    if (preg_match("/\.gif$/", $path))
+        return "image/gif";
+    if (preg_match("/\.jpg$/", $path))
+        return "image/jpeg";
+    if (preg_match("/\.png$/", $path))
+        return "image/png";
+    return "text/plain";
+}
+
+$path = $_GET['path'];
+$expectedReferer = $_GET['expected-referer'];
+$referer = $_SERVER["HTTP_REFERER"];
+
+if ($expectedReferer == $referer && file_exists($path)) {
+    header('HTTP/1.1 200 OK');
+    header("Cache-control: no-store");
+    header("Content-Type: " . contentType($path));
+    print file_get_contents($path);
+} else {
+    header('HTTP/1.1 404 Not Found');
+}
+
+?>

Added: trunk/LayoutTests/http/tests/cache/resources/permanent-redirect.php (0 => 190418)


--- trunk/LayoutTests/http/tests/cache/resources/permanent-redirect.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/resources/permanent-redirect.php	2015-10-01 18:09:07 UTC (rev 190418)
@@ -0,0 +1,6 @@
+<?
+$location = $_GET['location'];
+
+header('HTTP/1.1 301 Permanent Redirect');
+header('Location:' . $location);
+?>

Added: trunk/LayoutTests/http/tests/cache/resources/redirect-referer-iframe-expected.html (0 => 190418)


--- trunk/LayoutTests/http/tests/cache/resources/redirect-referer-iframe-expected.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/resources/redirect-referer-iframe-expected.html	2015-10-01 18:09:07 UTC (rev 190418)
@@ -0,0 +1 @@
+<img src=""

Added: trunk/LayoutTests/http/tests/cache/resources/redirect-referer-iframe.html (0 => 190418)


--- trunk/LayoutTests/http/tests/cache/resources/redirect-referer-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache/resources/redirect-referer-iframe.html	2015-10-01 18:09:07 UTC (rev 190418)
@@ -0,0 +1 @@
+<img src=""

Modified: trunk/Source/WebKit2/ChangeLog (190417 => 190418)


--- trunk/Source/WebKit2/ChangeLog	2015-10-01 17:45:59 UTC (rev 190417)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-01 18:09:07 UTC (rev 190418)
@@ -1,3 +1,20 @@
+2015-10-01  Antti Koivisto  <an...@apple.com>
+
+        Network cache: Subresource referer header wrong after cached redirect
+        https://bugs.webkit.org/show_bug.cgi?id=149709
+        rdar://problem/22917174
+
+        Reviewed by Chris Dumez.
+
+        If a main resource is loaded from a cache entry that involved redirects the document
+        will end up setting the Referer-headers of the subresources to the request URL not the redirected URL
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
+
+            If a cache entry involved a redirect synthesize a minimal willSendRequest message so that WebCore side
+            runs through the same code paths as when receiving a redirect from network.
+
 2015-10-01  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Websites with invalid auth header keep loading forever

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (190417 => 190418)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2015-10-01 17:45:59 UTC (rev 190417)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2015-10-01 18:09:07 UTC (rev 190418)
@@ -570,6 +570,14 @@
         m_synchronousLoadData->response = entry->response();
         sendReplyToSynchronousRequest(*m_synchronousLoadData, entry->buffer());
     } else {
+        if (entry->response().url() != originalRequest().url()) {
+            // This is a cached redirect. Synthesize a minimal redirect so we get things like referer header right.
+            // FIXME: We should cache the actual redirects.
+            ResourceRequest syntheticRedirectRequest(entry->response().url());
+            ResourceResponse syntheticRedirectResponse(originalRequest().url(), { }, 0, { });
+            sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(syntheticRedirectRequest, syntheticRedirectResponse));
+        }
+
         bool needsContinueDidReceiveResponseMessage = originalRequest().requester() == ResourceRequest::Requester::Main;
         sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponse(entry->response(), needsContinueDidReceiveResponseMessage));
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to