Resource Load Statistics: Downgrade all third-party referrer headers
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Sep 2019 05:13:10 +0000 (05:13 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Sep 2019 05:13:10 +0000 (05:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201353
<rdar://problem/54895650>
Source/WebKit:

Majority of this patch was written by John Wilander <wilander@apple.com>.

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

When tracking protections are enabled, we should downgrade all third-party
referrers to their origins. Note that this downgrade will be specific to
Cocoa so other ports will have to adopt as they see fit.

Cocoa already does this downgrade in ephemeral sessions (shipping).

The majority of these changes are test infrastructure. The functional
change is in WebKit::NetworkDataTaskCocoa and WebKit::NetworkSession.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::setShouldDowngradeReferrerForTesting):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::isResourceLoadStatisticsEnabled const):
(WebKit::NetworkSession::setShouldDowngradeReferrerForTesting):
(WebKit::NetworkSession::shouldDowngradeReferrer const):
* NetworkProcess/NetworkSession.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::isThirdPartyRequest const):
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
(WebKit::NetworkDataTaskCocoa::restrictRequestReferrerToOriginIfNeeded):
(WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
(WebKit::NetworkDataTaskCocoa::isThirdPartyRequest): Deleted.
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTesting):
(WKWebsiteDataStoreStatisticsResetToConsistentState):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::setShouldDowngradeReferrerForTesting):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::setResourceLoadStatisticsShouldDowngradeReferrerForTesting):
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

Majority of this patch was written by John Wilander <wilander@apple.com>.

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

The changes to the TestRunner facilitates an opt-out for test cases
that either test the referrer mechanism explicitly or tests that
rely on the full referrer to be sent.

The new boolean variable and early return in
TestRunner::setStatisticsShouldDowngradeReferrer() prevent the same
event from trying to set multiple TestRunner callbacks.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::didReceiveMessageToPage):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setStatisticsShouldDowngradeReferrer):
(WTR::TestRunner::statisticsCallDidSetShouldDowngradeReferrerCallback):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::setStatisticsShouldDowngradeReferrer):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
(WTR::TestInvocation::didSetShouldDowngradeReferrer):
* WebKitTestRunner/TestInvocation.h:

LayoutTests:

Majority of this patch was written by John Wilander <wilander@apple.com>

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

The changes in the two http/tests/resourceLoadStatistics/strip-referrer-to-origin*
tests and the http/tests/navigation/ping-attribute/* tests are for the functional
change. The other changes are to make use of the new
testRunner.setStatisticsShouldDowngradeReferrer() to maintain earlier functionality.

TestRunner::setStatisticsShouldDowngradeReferrer() function is not
supported for mac-wk1, win or wincairo.

* http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt:
* http/tests/navigation/ping-attribute/anchor-cross-origin.html:
* http/tests/navigation/ping-attribute/area-cross-origin.html:
* http/tests/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http-http.html:
* http/tests/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http.https.html:
* http/tests/referrer-policy-script/no-referrer-when-downgrade/same-origin.html:
* http/tests/referrer-policy-script/no-referrer/cross-origin-http-http.html:
* http/tests/referrer-policy-script/no-referrer/cross-origin-http.https.html:
* http/tests/referrer-policy-script/no-referrer/same-origin.html:
* http/tests/referrer-policy-script/origin-when-cross-origin/cross-origin-http-http.html:
* http/tests/referrer-policy-script/origin-when-cross-origin/cross-origin-http.https.html:
* http/tests/referrer-policy-script/origin-when-cross-origin/same-origin.html:
* http/tests/referrer-policy-script/origin/cross-origin-http-http.html:
* http/tests/referrer-policy-script/origin/cross-origin-http.https.html:
* http/tests/referrer-policy-script/origin/same-origin.html:
* http/tests/referrer-policy-script/same-origin/cross-origin-http-http.html:
* http/tests/referrer-policy-script/same-origin/cross-origin-http.https.html:
* http/tests/referrer-policy-script/same-origin/same-origin.html:
* http/tests/referrer-policy-script/strict-origin-when-cross-origin/cross-origin-http-http.html:
* http/tests/referrer-policy-script/strict-origin-when-cross-origin/cross-origin-http.https.html:
* http/tests/referrer-policy-script/strict-origin-when-cross-origin/same-origin.html:
* http/tests/referrer-policy-script/strict-origin/cross-origin-http-http.html:
* http/tests/referrer-policy-script/strict-origin/cross-origin-http.https.html:
* http/tests/referrer-policy-script/strict-origin/same-origin.html:
* http/tests/referrer-policy-script/unsafe-url/cross-origin-http-http.html:
* http/tests/referrer-policy-script/unsafe-url/cross-origin-http.https.html:
* http/tests/referrer-policy-script/unsafe-url/same-origin.html:
* http/tests/referrer-policy/no-referrer-when-downgrade/cross-origin-http-http.html:
* http/tests/referrer-policy/no-referrer-when-downgrade/cross-origin-http.https.html:
* http/tests/referrer-policy/no-referrer-when-downgrade/same-origin.html:
* http/tests/referrer-policy/unsafe-url/cross-origin-http-http.html:
* http/tests/referrer-policy/unsafe-url/cross-origin-http.https.html:
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html: Removed.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects-expected.txt: Renamed from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-expected.txt.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html: Copied from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests-expected.txt: Renamed from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-expected.txt.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html: Renamed from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html.
* http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies-when-private-browsing-enabled.php:
* http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies.php:
* http/tests/security/referrer-policy-header.html:
* platform/ios-wk2/TestExpectations:
* platform/ios/TestExpectations:
* platform/mac-wk1/TestExpectations:
* platform/mac-wk2/TestExpectations:
* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:
* platform/wk2/TestExpectations:
* resources/testharnessreport.js:
* resources/js-test.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250413 268f45cc-cd09-0410-ab3c-d52691b4dbfc

73 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt
LayoutTests/http/tests/navigation/ping-attribute/anchor-cross-origin.html
LayoutTests/http/tests/navigation/ping-attribute/area-cross-origin.html
LayoutTests/http/tests/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/no-referrer-when-downgrade/same-origin.html
LayoutTests/http/tests/referrer-policy-script/no-referrer/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/no-referrer/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/no-referrer/same-origin.html
LayoutTests/http/tests/referrer-policy-script/origin-when-cross-origin/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/origin-when-cross-origin/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/origin-when-cross-origin/same-origin.html
LayoutTests/http/tests/referrer-policy-script/origin/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/origin/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/origin/same-origin.html
LayoutTests/http/tests/referrer-policy-script/same-origin/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/same-origin/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/same-origin/same-origin.html
LayoutTests/http/tests/referrer-policy-script/strict-origin-when-cross-origin/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/strict-origin-when-cross-origin/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/strict-origin-when-cross-origin/same-origin.html
LayoutTests/http/tests/referrer-policy-script/strict-origin/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/strict-origin/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/strict-origin/same-origin.html
LayoutTests/http/tests/referrer-policy-script/unsafe-url/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy-script/unsafe-url/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy-script/unsafe-url/same-origin.html
LayoutTests/http/tests/referrer-policy/no-referrer-when-downgrade/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy/no-referrer-when-downgrade/cross-origin-http.https.html
LayoutTests/http/tests/referrer-policy/no-referrer-when-downgrade/same-origin.html
LayoutTests/http/tests/referrer-policy/unsafe-url/cross-origin-http-http.html
LayoutTests/http/tests/referrer-policy/unsafe-url/cross-origin-http.https.html
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html [deleted file]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects-expected.txt [moved from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-expected.txt with 60% similarity]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests-expected.txt [moved from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-expected.txt with 65% similarity]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html [moved from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html with 53% similarity]
LayoutTests/http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies-when-private-browsing-enabled.php
LayoutTests/http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies.php
LayoutTests/http/tests/security/referrer-policy-header.html
LayoutTests/platform/ios-wk2/TestExpectations
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/platform/win/TestExpectations
LayoutTests/platform/wincairo/TestExpectations
LayoutTests/platform/wk2/TestExpectations
LayoutTests/resources/js-test.js
LayoutTests/resources/testharnessreport.js
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/NetworkProcess/NetworkSession.cpp
Source/WebKit/NetworkProcess/NetworkSession.h
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h
Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp
Tools/WebKitTestRunner/TestInvocation.h

index 65e4c62..0ee7e0a 100644 (file)
@@ -1,3 +1,71 @@
+2019-09-26  Kate Cheney  <katherine_cheney@apple.com>
+
+        Resource Load Statistics: Downgrade all third-party referrer headers
+        https://bugs.webkit.org/show_bug.cgi?id=201353
+        <rdar://problem/54895650>
+
+        Majority of this patch was written by John Wilander <wilander@apple.com>
+
+        Reviewed by Brent Fulgham. 
+
+        The changes in the two http/tests/resourceLoadStatistics/strip-referrer-to-origin*
+        tests and the http/tests/navigation/ping-attribute/* tests are for the functional 
+        change. The other changes are to make use of the new
+        testRunner.setStatisticsShouldDowngradeReferrer() to maintain earlier functionality.
+
+        TestRunner::setStatisticsShouldDowngradeReferrer() function is not
+        supported for mac-wk1, win or wincairo.
+
+        * http/tests/blink/sendbeacon/beacon-cross-origin-expected.txt:
+        * http/tests/navigation/ping-attribute/anchor-cross-origin.html:
+        * http/tests/navigation/ping-attribute/area-cross-origin.html:
+        * http/tests/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/no-referrer-when-downgrade/same-origin.html:
+        * http/tests/referrer-policy-script/no-referrer/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/no-referrer/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/no-referrer/same-origin.html:
+        * http/tests/referrer-policy-script/origin-when-cross-origin/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/origin-when-cross-origin/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/origin-when-cross-origin/same-origin.html:
+        * http/tests/referrer-policy-script/origin/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/origin/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/origin/same-origin.html:
+        * http/tests/referrer-policy-script/same-origin/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/same-origin/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/same-origin/same-origin.html:
+        * http/tests/referrer-policy-script/strict-origin-when-cross-origin/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/strict-origin-when-cross-origin/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/strict-origin-when-cross-origin/same-origin.html:
+        * http/tests/referrer-policy-script/strict-origin/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/strict-origin/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/strict-origin/same-origin.html:
+        * http/tests/referrer-policy-script/unsafe-url/cross-origin-http-http.html:
+        * http/tests/referrer-policy-script/unsafe-url/cross-origin-http.https.html:
+        * http/tests/referrer-policy-script/unsafe-url/same-origin.html:
+        * http/tests/referrer-policy/no-referrer-when-downgrade/cross-origin-http-http.html:
+        * http/tests/referrer-policy/no-referrer-when-downgrade/cross-origin-http.https.html:
+        * http/tests/referrer-policy/no-referrer-when-downgrade/same-origin.html:
+        * http/tests/referrer-policy/unsafe-url/cross-origin-http-http.html:
+        * http/tests/referrer-policy/unsafe-url/cross-origin-http.https.html:
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html: Removed.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects-expected.txt: Renamed from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-expected.txt.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html: Copied from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests-expected.txt: Renamed from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-expected.txt.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html: Renamed from LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html.
+        * http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies-when-private-browsing-enabled.php:
+        * http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies.php:
+        * http/tests/security/referrer-policy-header.html:
+        * platform/ios-wk2/TestExpectations:
+        * platform/ios/TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+        * platform/mac-wk2/TestExpectations:
+        * platform/win/TestExpectations:
+        * platform/wincairo/TestExpectations:
+        * platform/wk2/TestExpectations:
+        * resources/testharnessreport.js:
+        * resources/js-test.js:
+
 2019-09-26  Eric Carlson  <eric.carlson@apple.com>
 
         REGRESSION (iOS 13): Trying to record just audio using HTML Media Capture crashes Safari
index 76c01a5..a899827 100644 (file)
@@ -7,7 +7,7 @@ PASS navigator.sendBeacon("http://localhost:8000/blink/sendbeacon/resources/save
 PASS Beacon sent successfully
 PASS Content-Type: text/plain;charset=UTF-8
 PASS Origin: http://127.0.0.1:8000
-PASS Referer: http://127.0.0.1:8000/blink/sendbeacon/beacon-cross-origin.html
+PASS Referer: http://127.0.0.1:8000/
 PASS Request-Method: POST
 PASS Length: 11
 PASS Body: CrossOrigin
index 7004798..6dca8c1 100644 (file)
@@ -10,6 +10,7 @@ var testCalled = false;
 function test() {
     if (!testCalled) {
         if (window.testRunner && window.internals) {
+            testRunner.setStatisticsShouldDowngradeReferrer(false, function () { });
             testRunner.dumpAsText();
             internals.settings.setHyperlinkAuditingEnabled(true);
             testRunner.waitUntilDone();
index 4e53f14..1891b3f 100644 (file)
@@ -5,6 +5,7 @@
 <script>
 if (window.testRunner && window.internals) {
     testRunner.dumpAsText();
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { });
     internals.settings.setHyperlinkAuditingEnabled(true);
     testRunner.waitUntilDone();
 }
index f3e7b2a..4e66522 100644 (file)
@@ -3,7 +3,7 @@
 <head>
 <script src="/js-test-resources/js-test.js"></script>
 </head>
-<body>
+<body onload="runTest()">
 <script>
 description("Tests the behavior of no-referrer-when-downgrade referrer policy when cross origin.");
 jsTestIsAsync = true;
@@ -14,7 +14,14 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/no-referrer-when-downgrade/cross-origin-http-http.html");
     finishJSTest();
 }
+
+function runTest() {
+    if (window.testRunner) {
+        setTimeout(function() {
+            testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('no-referrer-when-downgrade', 'localhost')});
+        }, 1000);
+    }
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="no-referrer-when-downgrade"></script>
 </body>
 </html>
index 4b77685..dcf4f6a 100644 (file)
@@ -17,7 +17,11 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+      downgradeReferrerCallback('no-referrer-when-downgrade', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="no-referrer-when-downgrade"></script>
 </body>
 </html>
index 0fb8e43..f82d6fe 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/no-referrer-when-downgrade/same-origin.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('no-referrer-when-downgrade', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy=no-referrer-when-downgrade"></script>
 </body>
 </html>
index f79f9b6..f06c8c9 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('no-referrer', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="no-referrer"></script>
 </body>
 </html>
index 12443dc..f268cb9 100644 (file)
@@ -17,7 +17,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function() { downgradeReferrerCallback('no-referrer', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="no-referrer"></script>
 </body>
 </html>
index 3428312..d875f4f 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('no-referrer', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="no-referrer"></script>
 </body>
 </html>
index 8392057..0b6bd64 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('origin-when-cross-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="origin-when-cross-origin"></script>
 </body>
 </html>
index dbf29e4..1cd17a2 100644 (file)
@@ -17,7 +17,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "https://127.0.0.1:8443/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('origin-when-cross-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="origin-when-cross-origin"></script>
 </body>
 </html>
index f0ba675..7a23c90 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/origin-when-cross-origin/same-origin.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('origin-when-cross-origin', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="origin-when-cross-origin"></script>
 </body>
 </html>
index 38335b7..90018b8 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="origin"></script>
 </body>
 </html>
index c34cb09..070bb56 100644 (file)
@@ -17,7 +17,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "https://127.0.0.1:8443/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="origin"></script>
 </body>
 </html>
index 260ac62..1bcb7c8 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('origin', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="origin"></script>
 </body>
 </html>
index 8b73c72..4fdc042 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('same-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="same-origin"></script>
 </body>
 </html>
index c0917d7..d9a6d82 100644 (file)
@@ -17,7 +17,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('same-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="same-origin"></script>
 </body>
 </html>
index 10c0327..e0f169f 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/same-origin/same-origin.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('same-origin', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="same-origin"></script>
 </body>
 </html>
index d0706b9..2aac82c 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('strict-origin-when-cross-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="strict-origin-when-cross-origin"></script>
 </body>
 </html>
index d46b02a..c531c03 100644 (file)
@@ -17,7 +17,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('strict-origin-when-top-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="strict-origin-when-cross-origin"></script>
 </body>
 </html>
index 3bd3f4d..65856f7 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/strict-origin-when-cross-origin/same-origin.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('strict-origin-when-cross-origin', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="strict-origin-when-cross-origin"></script>
 </body>
 </html>
index 2692961..38bee47 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('strict-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="strict-origin"></script>
 </body>
 </html>
index 541c370..d321680 100644 (file)
@@ -17,7 +17,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('strict-origin', 'localhost')});
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="strict-origin"></script>
 </body>
 </html>
index 21ee311..b977f56 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('strict-origin', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="strict-origin"></script>
 </body>
 </html>
index 71e1bfa..5924817 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/unsafe-url/cross-origin-http-http.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('unsafe-url', 'localhost') });
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="unsaf-url"></script>
 </body>
 </html>
index 0c1ac03..9664cd8 100644 (file)
@@ -17,7 +17,12 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "https://127.0.0.1:8443/referrer-policy-script/unsafe-url/cross-origin-http.https.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        downgradeReferrerCallback('unsafe-url', 'localhost');
+    });
+}
 </script>
-<script src="http://localhost:8000/referrer-policy/resources/script.php" referrerpolicy="unsafe-url"></script>
 </body>
 </html>
index e5eddeb..7b69d15 100644 (file)
@@ -14,7 +14,10 @@ function checkReferrer(value) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy-script/unsafe-url/same-origin.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () { downgradeReferrerCallback('unsafe-url', '127.0.0.1')});
+}
 </script>
-<script src="http://127.0.0.1:8000/referrer-policy/resources/script.php" referrerpolicy="unsafe-url"></script>
 </body>
 </html>
index 08086d0..4c94f1d 100644 (file)
@@ -15,7 +15,14 @@ window.onmessage = function(event) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy/no-referrer-when-downgrade/cross-origin-http-http.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        let iframeElement = document.createElement("iframe");
+        iframeElement.src = "http://localhost:8000/referrer-policy/resources/document.html";
+        document.body.appendChild(iframeElement);
+    });
+}
 </script>
-<iframe src="http://localhost:8000/referrer-policy/resources/document.html"></iframe>
 </body>
 </html>
index ab4b2e2..d6051ce 100644 (file)
@@ -18,7 +18,14 @@ window.onmessage = function(event) {
     shouldBeEqualToString("referrer", "");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        let iframeElement = document.createElement("iframe");
+        iframeElement.src = "http://localhost:8000/referrer-policy/resources/document.html";
+        document.body.appendChild(iframeElement);
+    });
+}
 </script>
-<iframe src="http://localhost:8000/referrer-policy/resources/document.html"></iframe>
 </body>
 </html>
index a39e691..7a205d7 100644 (file)
@@ -15,7 +15,14 @@ window.onmessage = function(event) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy/no-referrer-when-downgrade/same-origin.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        let iframeElement = document.createElement("iframe");
+        iframeElement.src = "http://127.0.0.1:8000/referrer-policy/resources/document.html";
+        document.body.appendChild(iframeElement);
+    });
+}
 </script>
-<iframe src="http://127.0.0.1:8000/referrer-policy/resources/document.html"></iframe>
 </body>
 </html>
index 36eeb63..bba42ba 100644 (file)
@@ -15,7 +15,14 @@ window.onmessage = function(event) {
     shouldBeEqualToString("referrer", "http://127.0.0.1:8000/referrer-policy/unsafe-url/cross-origin-http-http.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        let iframeElement = document.createElement("iframe");
+        iframeElement.src = "http://localhost:8000/referrer-policy/resources/document.html";
+        document.body.appendChild(iframeElement);
+    });
+}
 </script>
-<iframe src="http://localhost:8000/referrer-policy/resources/document.html"></iframe>
 </body>
 </html>
index 4c391a3..ffcd6e7 100644 (file)
@@ -18,7 +18,14 @@ window.onmessage = function(event) {
     shouldBeEqualToString("referrer", "https://127.0.0.1:8443/referrer-policy/unsafe-url/cross-origin-http.https.html");
     finishJSTest();
 }
+
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        let iframeElement = document.createElement("iframe");
+        iframeElement.src = "http://localhost:8000/referrer-policy/resources/document.html";
+        document.body.appendChild(iframeElement);
+    });
+}
 </script>
-<iframe src="http://localhost:8000/referrer-policy/resources/document.html"></iframe>
 </body>
 </html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html b/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html
deleted file mode 100644 (file)
index cd7c9cc..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-    <script src="/js-test-resources/js-test.js"></script>
-    <script src="resources/util.js"></script>
-</head>
-<body>
-<script>
-    description("Tests that only the origin is sent as referrer for prevalent resources without user interaction.");
-    jsTestIsAsync = true;
-    testRunner.dumpChildFramesAsText();
-
-    function openIframe(url, onLoadHandler) {
-        const element = document.createElement("iframe");
-        element.src = url;
-        if (onLoadHandler) {
-            element.onload = onLoadHandler;
-        }
-        document.body.appendChild(element);
-    }
-
-    var referrer;
-    setEnableFeature(true, function() {
-        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
-            testFailed("Localhost was classified as prevalent resource before the test started.");
-
-        fetch("resources/echo-referrer.php").then(function(response) {
-            return response.text();
-        }).then(function(data) {
-            referrer = data;
-            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html");
-
-            testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
-                if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
-                    testFailed("Host did not get set as prevalent resource.");
-
-                testRunner.statisticsUpdateCookieBlocking(function() {
-                    fetch("http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php").then(function(response) {
-                        return response.text();
-                    }).then(function(data) {
-                        referrer = data;
-                        shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
-
-                        openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
-                            setEnableFeature(false, finishJSTest);
-                        });
-
-                    }).catch(function(error) {
-                        console.log(error.message);
-                        setEnableFeature(false, finishJSTest);
-                    });
-                });
-            });
-        }).catch(function(error) {
-            console.log(error.message);
-            setEnableFeature(false, finishJSTest);
-        });
-    });
-</script>
-</body>
-</html>
@@ -1,9 +1,9 @@
-Tests that only the origin is sent as referrer in redirects to prevalent resources without user interaction.
+Tests that only the origin is sent as referrer in redirects to third-parties.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS referrer is "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html"
+PASS referrer is "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html"
 PASS successfullyParsed is true
 
 TEST COMPLETE
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html b/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html
new file mode 100644 (file)
index 0000000..24b557d
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Tests that only the origin is sent as referrer in redirects to third-parties.");
+    jsTestIsAsync = true;
+    testRunner.dumpChildFramesAsText();
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    let referrer;
+    setEnableFeature(true, function() {
+        fetch("resources/echo-referrer.php").then(function(response) {
+            return response.text();
+        }).then(function(data) {
+            referrer = data;
+            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html");
+
+            openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function () {
+                setEnableFeature(false, finishJSTest);
+            });
+        }).catch(function(error) {
+            console.log(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    });
+</script>
+</body>
+</html>
@@ -1,9 +1,9 @@
-Tests that only the origin is sent as referrer for prevalent resources without user interaction.
+Tests that only the origin is sent as referrer for third-party requests.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS referrer is "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html"
+PASS referrer is "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html"
 PASS referrer is "http://127.0.0.1:8000/"
 PASS successfullyParsed is true
 
@@ -6,7 +6,7 @@
 </head>
 <body>
 <script>
-    description("Tests that only the origin is sent as referrer in redirects to prevalent resources without user interaction.");
+    description("Tests that only the origin is sent as referrer for third-party requests.");
     jsTestIsAsync = true;
     testRunner.dumpChildFramesAsText();
 
         document.body.appendChild(element);
     }
 
-    var referrer;
+    let referrer;
     setEnableFeature(true, function() {
-        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
-            testFailed("Localhost was classified as prevalent resource before the test started.");
-
         fetch("resources/echo-referrer.php").then(function(response) {
             return response.text();
         }).then(function(data) {
             referrer = data;
-            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html");
+            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html");
 
-            testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
-                if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
-                    testFailed("Host did not get set as prevalent resource.");
+            fetch("http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php").then(function(response) {
+                return response.text();
+            }).then(function(data) {
+                referrer = data;
+                shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
 
-                testRunner.statisticsUpdateCookieBlocking(function() {
-                    openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
-                        setEnableFeature(false, finishJSTest);
-                    });
+                openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
+                    setEnableFeature(false, finishJSTest);
                 });
+
+            }).catch(function(error) {
+                console.log(error.message);
+                setEnableFeature(false, finishJSTest);
             });
         }).catch(function(error) {
             console.log(error.message);
index eb7821e..01bd622 100644 (file)
@@ -6,15 +6,25 @@
 <html>
 <body>
 <script>
-    var xhr = new XMLHttpRequest();
-    xhr.open("GET", "http://localhost:8080/cookies/resources/setCookies.cgi", false);
-    xhr.setRequestHeader("SET-COOKIE", "hello=world;path=/");
-    xhr.send(null);
-</script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
 
-<!-- This image will generate a CSP violation report. -->
-<img src="/security/resources/abe.png">
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", "http://localhost:8080/cookies/resources/setCookies.cgi", false);
+        xhr.setRequestHeader("SET-COOKIE", "hello=world;path=/");
+        xhr.send(null);
 
-<script src="resources/go-to-echo-report.js"></script>
+        // This image will generate a CSP violation report.
+        let imgElement = document.createElement("img");
+        imgElement.onload = imgElement.onerror = function () {
+            window.location = "/security/contentSecurityPolicy/resources/echo-report.php";
+        };
+        imgElement.src = "/security/resources/abe.png";
+        document.body.appendChild(imgElement);
+    });
+}
+</script>
 </body>
 </html>
index 62d3180..a5a3f74 100644 (file)
@@ -5,15 +5,25 @@
 <html>
 <body>
 <script>
-    var xhr = new XMLHttpRequest();
-    xhr.open("GET", "http://localhost:8080/cookies/resources/setCookies.cgi", false);
-    xhr.setRequestHeader("SET-COOKIE", "hello=world;path=/");
-    xhr.send(null);
-</script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
 
-<!-- This image will generate a CSP violation report. -->
-<img src="/security/resources/abe.png">
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", "http://localhost:8080/cookies/resources/setCookies.cgi", false);
+        xhr.setRequestHeader("SET-COOKIE", "hello=world;path=/");
+        xhr.send(null);
 
-<script src="resources/go-to-echo-report.js"></script>
+        // This image will generate a CSP violation report.
+        let imgElement = document.createElement("img");
+        imgElement.onload = imgElement.onerror = function () {
+            window.location = "/security/contentSecurityPolicy/resources/echo-report.php";
+        };
+        imgElement.src = "/security/resources/abe.png";
+        document.body.appendChild(imgElement);
+    });
+}
+</script>
 </body>
 </html>
index 95ad042..0a14bc3 100644 (file)
@@ -82,7 +82,11 @@ function runNextTest()
     document.body.appendChild(frame);    
 }
 
-runNextTest();
+if (window.testRunner) {
+    testRunner.setStatisticsShouldDowngradeReferrer(false, function () {
+        runNextTest();
+    });
+}
 </script>
 </body>
 </html>
index 37b2437..d7e98a9 100644 (file)
@@ -67,6 +67,10 @@ http/tests/webAPIStatistics [ Skip ]
 scrollingcoordinator/non-fast-scrollable-region-scaled-iframe.html [ Skip ]
 scrollingcoordinator/non-fast-scrollable-region-transformed-iframe.html [ Skip ]
 
+# Cocoa-specific
+http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html [ Pass ]
+http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html [ Pass ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific directories.
 #//////////////////////////////////////////////////////////////////////////////////////////
index 9c9471a..412fb23 100644 (file)
@@ -2793,8 +2793,8 @@ http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect.html [ Pass
 http/tests/resourceLoadStatistics/grandfathering.html [ Pass ]
 http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store.html [ Pass ]
 http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html [ Pass ]
-http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html [ Pass ]
-http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html [ Pass ]
+http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html [ Pass ]
+http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html [ Pass ]
 http/tests/storageAccess/deny-storage-access-under-opener.html [ Pass ]
 http/tests/storageAccess/deny-storage-access-under-opener-if-auto-dismiss.html [ Pass ]
 http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html [ Pass ]
index 84df856..b00cbd6 100644 (file)
@@ -132,6 +132,17 @@ http/tests/security/contentSecurityPolicy/connect-src-beacon-allowed.html [ Skip
 http/tests/security/contentSecurityPolicy/connect-src-beacon-blocked.html [ Skip ]
 http/tests/security/contentSecurityPolicy/report-only-connect-src-beacon-redirect-blocked.php [ Skip ]
 
+# testRunner.setStatisticsShouldDowngradeReferrer() is not supported on WK1
+http/tests/referrer-policy-script/ [ Skip ]
+http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies.php [ Skip ] 
+http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies-when-private-browsing-enabled.php [ Skip ] 
+http/tests/security/referrer-policy-header.html [ Skip ] 
+http/tests/navigation/ping-attribute/area-cross-origin.html [ Skip ] 
+http/tests/navigation/ping-attribute/anchor-cross-origin.html [ Skip ] 
+http/tests/referrer-policy/no-referrer-when-downgrade/ [ Skip ] 
+http/tests/referrer-policy/unsafe-url/cross-origin-http-http.html [ Skip ] 
+http/tests/referrer-policy/unsafe-url/cross-origin-http.https.html [ Skip ] 
+
 # Not supported on WK1
 http/tests/intersection-observer [ Skip ]
 imported/w3c/web-platform-tests/intersection-observer [ Skip ]
index db1da1b..200ee9a 100644 (file)
@@ -774,13 +774,11 @@ webkit.org/b/185994 fast/text/user-installed-fonts/shadow-postscript-family.html
 [ HighSierra+ ] http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/grandfathering.html [ Pass ]
-[ HighSierra+ ] http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html [ Pass ]
-[ HighSierra+ ] http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html [ Pass ]
+[ HighSierra+ ] http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html [ Pass ]
 
 # Skipped in general expectations since they only work on iOS and Mac, WK2.
-http/tests/security/strip-referrer-to-origin-for-third-party-redirects-in-private-mode.html [ Pass ]
-http/tests/security/strip-referrer-to-origin-for-third-party-requests-in-private-mode.html [ Pass ]
 media/deactivate-audio-session.html [ Pass ]
 
 # Link preconnect is disabled on pre-High Sierra because the CFNetwork SPI is missing.
index c512ca0..6c5047a 100644 (file)
@@ -142,6 +142,15 @@ http/tests/misc/willCacheResponse-delegate-callback.html [ Skip ]
 # testRunner.setAlwaysAcceptCookies() is not implemented on Windows.
 http/tests/xmlhttprequest/cross-origin-cookie-storage.html [ Skip ]
 
+# testRunner.setStatisticsShouldDowngradeReferrer() is not supported on Windows
+http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies.php [ Skip ] 
+http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies-when-private-browsing-enabled.php [ Skip ] 
+http/tests/navigation/ping-attribute/area-cross-origin.html [ Skip ] 
+http/tests/navigation/ping-attribute/anchor-cross-origin.html [ Skip ] 
+http/tests/referrer-policy/no-referrer-when-downgrade/ [ Skip ] 
+http/tests/referrer-policy/unsafe-url/cross-origin-http-http.html [ Skip ] 
+http/tests/referrer-policy/unsafe-url/cross-origin-http.https.html [ Skip ] 
+
 # Dark mode not supported on Windows
 css-dark-mode [ Skip ]
 
index b1ea2be..a7e5c72 100644 (file)
@@ -936,6 +936,16 @@ http/tests/quicklook [ Skip ]
 http/tests/referrer-policy-iframe [ Skip ]
 http/tests/referrer-policy-script [ Skip ]
 
+# testRunner.setStatisticsShouldDowngradeReferrer() is not supported
+http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies.php [ Skip ] 
+http/tests/security/contentSecurityPolicy/report-cross-origin-no-cookies-when-private-browsing-enabled.php [ Skip ] 
+http/tests/security/referrer-policy-header.html [ Skip ] 
+http/tests/navigation/ping-attribute/area-cross-origin.html [ Skip ] 
+http/tests/navigation/ping-attribute/anchor-cross-origin.html [ Skip ] 
+http/tests/referrer-policy/no-referrer-when-downgrade/ [ Skip ] 
+http/tests/referrer-policy/unsafe-url/cross-origin-http-http.html [ Skip ] 
+http/tests/referrer-policy/unsafe-url/cross-origin-http.https.html [ Skip ] 
+
 # All timing out
 http/tests/resourceLoadStatistics [ Skip ]
 
index 384afb5..e3fabbd 100644 (file)
@@ -743,8 +743,8 @@ http/tests/websocket/connection-refusal-in-frame-resource-load-statistics.html [
 # These are only supported behind a compile time flag in macOS High Sierra + iOS 11, and above.
 http/tests/resourceLoadStatistics/cookie-deletion.html [ Skip ]
 http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction.html [ Skip ]
-http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects.html [ Skip ]
-http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests.html [ Skip ]
+http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-redirects.html [ Skip ]
+http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-third-party-requests.html [ Skip ]
 http/tests/resourceLoadStatistics/add-blocking-to-redirect.html [ Skip ]
 http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect.html [ Skip ]
 http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html [ Skip ]
index e056492..68a456a 100644 (file)
@@ -895,3 +895,10 @@ if (isWorker()) {
         workerPort.postMessage(msg);
     };
 }
+
+function downgradeReferrerCallback(policy, host) {
+    let scriptElement = document.createElement("script");
+    scriptElement.src = "http://".concat(host, ":8000/referrer-policy/resources/script.php");
+    scriptElement.referrerPolicy = policy;
+    document.body.appendChild(scriptElement);
+}
index d9842f8..bcb7afb 100644 (file)
@@ -27,6 +27,9 @@ if (self.testRunner) {
         self.AudioContext = self.webkitAudioContext;
         self.OfflineAudioContext = self.webkitOfflineAudioContext;
     }
+
+    if (testRunner.setStatisticsShouldDowngradeReferrer) 
+       testRunner.setStatisticsShouldDowngradeReferrer(false, function() { });
 }
 
 if (self.internals && internals.setDisableGetDisplayMediaUserGestureConstraint)
index 19e235b..f03686c 100644 (file)
@@ -1,3 +1,49 @@
+2019-09-26  Kate Cheney  <katherine_cheney@apple.com>
+
+        Resource Load Statistics: Downgrade all third-party referrer headers
+        https://bugs.webkit.org/show_bug.cgi?id=201353
+        <rdar://problem/54895650>
+        
+        Majority of this patch was written by John Wilander <wilander@apple.com>.
+
+        Reviewed by Brent Fulgham. 
+
+        When tracking protections are enabled, we should downgrade all third-party
+        referrers to their origins. Note that this downgrade will be specific to
+        Cocoa so other ports will have to adopt as they see fit.
+
+        Cocoa already does this downgrade in ephemeral sessions (shipping).
+
+        The majority of these changes are test infrastructure. The functional
+        change is in WebKit::NetworkDataTaskCocoa and WebKit::NetworkSession.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::setShouldDowngradeReferrerForTesting):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        * NetworkProcess/NetworkSession.cpp:
+        (WebKit::NetworkSession::isResourceLoadStatisticsEnabled const):
+        (WebKit::NetworkSession::setShouldDowngradeReferrerForTesting):
+        (WebKit::NetworkSession::shouldDowngradeReferrer const):
+        * NetworkProcess/NetworkSession.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::isThirdPartyRequest const):
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        (WebKit::NetworkDataTaskCocoa::restrictRequestReferrerToOriginIfNeeded):
+        (WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
+        (WebKit::NetworkDataTaskCocoa::isThirdPartyRequest): Deleted.
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTesting):
+        (WKWebsiteDataStoreStatisticsResetToConsistentState):
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::setShouldDowngradeReferrerForTesting):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::setResourceLoadStatisticsShouldDowngradeReferrerForTesting):
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2019-09-26  Eric Carlson  <eric.carlson@apple.com>
 
         REGRESSION (iOS 13): Trying to record just audio using HTML Media Capture crashes Safari
index e218737..4611a73 100644 (file)
@@ -1242,6 +1242,14 @@ void NetworkProcess::hasIsolatedSession(PAL::SessionID sessionID, const WebCore:
         result = networkSession->hasIsolatedSession(domain);
     completionHandler(result);
 }
+
+void NetworkProcess::setShouldDowngradeReferrerForTesting(bool enabled, CompletionHandler<void()>&& completionHandler)
+{
+    forEachNetworkSession([enabled](auto& networkSession) {
+        networkSession.setShouldDowngradeReferrerForTesting(enabled);
+    });
+    completionHandler();
+}
 #endif // ENABLE(RESOURCE_LOAD_STATISTICS)
 
 bool NetworkProcess::sessionIsControlledByAutomation(PAL::SessionID sessionID) const
index bf5db7f..9d56f1a 100644 (file)
@@ -265,6 +265,7 @@ public:
     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
     void hasIsolatedSession(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
     bool isITPDatabaseEnabled() const { return m_isITPDatabaseEnabled; }
+    void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
 #endif
 
     using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
index c9e1aea..032f9f4 100644 (file)
@@ -137,6 +137,7 @@ messages -> NetworkProcess LegacyReceiver {
     ResetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID sessionID) -> () Async
     DeleteCookiesForTesting(PAL::SessionID sessionID, WebCore::RegistrableDomain domain, bool includeHttpOnlyCookies) -> () Async
     HasIsolatedSession(PAL::SessionID sessionID, WebCore::RegistrableDomain domain) -> (bool hasIsolatedSession) Async
+    SetShouldDowngradeReferrerForTesting(bool enabled) -> () Async
 #endif
 
     SetSessionIsControlledByAutomation(PAL::SessionID sessionID, bool controlled);
index e5fdaf4..0902869 100644 (file)
@@ -175,6 +175,11 @@ void NetworkSession::recreateResourceLoadStatisticStore()
     m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory, m_shouldIncludeLocalhostInResourceLoadStatistics);
 }
 
+bool NetworkSession::isResourceLoadStatisticsEnabled() const
+{
+    return !!m_resourceLoadStatistics;
+}
+
 void NetworkSession::notifyResourceLoadStatisticsProcessed()
 {
     m_networkProcess->parentProcessConnection()->send(Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed(), 0);
@@ -199,6 +204,17 @@ void NetworkSession::registrableDomainsWithWebsiteData(OptionSet<WebsiteDataType
 {
     m_networkProcess->registrableDomainsWithWebsiteData(m_sessionID, dataTypes, shouldNotifyPage, WTFMove(completionHandler));
 }
+
+void NetworkSession::setShouldDowngradeReferrerForTesting(bool enabled)
+{
+    m_downgradeReferrer = enabled;
+}
+
+bool NetworkSession::shouldDowngradeReferrer() const
+{
+    return m_downgradeReferrer;
+}
+
 #endif // ENABLE(RESOURCE_LOAD_STATISTICS)
 
 void NetworkSession::storeAdClickAttribution(WebCore::AdClickAttribution&& adClickAttribution)
index 53e9ff7..b182c69 100644 (file)
@@ -85,6 +85,7 @@ public:
     WebResourceLoadStatisticsStore* resourceLoadStatistics() const { return m_resourceLoadStatistics.get(); }
     void setResourceLoadStatisticsEnabled(bool);
     void recreateResourceLoadStatisticStore();
+    bool isResourceLoadStatisticsEnabled() const;
     void notifyResourceLoadStatisticsProcessed();
     void deleteWebsiteDataForRegistrableDomains(OptionSet<WebsiteDataType>, Vector<std::pair<WebCore::RegistrableDomain, WebsiteDataToRemove>>&&, bool shouldNotifyPage, CompletionHandler<void(const HashSet<WebCore::RegistrableDomain>&)>&&);
     void registrableDomainsWithWebsiteData(OptionSet<WebsiteDataType>, bool shouldNotifyPage, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&);
@@ -95,6 +96,8 @@ public:
     bool shouldIsolateSessionsForPrevalentTopFrames() const { return m_enableResourceLoadStatisticsNSURLSessionSwitching == EnableResourceLoadStatisticsNSURLSessionSwitching::Yes; }
     virtual bool hasIsolatedSession(const WebCore::RegistrableDomain) const { return false; }
     virtual void clearIsolatedSessions() { }
+    void setShouldDowngradeReferrerForTesting(bool);
+    bool shouldDowngradeReferrer() const;
 #endif
     void storeAdClickAttribution(WebCore::AdClickAttribution&&);
     void handleAdClickAttributionConversion(WebCore::AdClickAttribution::Conversion&&, const URL& requestURL, const WebCore::ResourceRequest& redirectRequest);
@@ -137,6 +140,7 @@ protected:
     WebCore::RegistrableDomain m_resourceLoadStatisticsManualPrevalentResource;
     EnableResourceLoadStatisticsNSURLSessionSwitching m_enableResourceLoadStatisticsNSURLSessionSwitching { EnableResourceLoadStatisticsNSURLSessionSwitching::No };
     bool m_enableResourceLoadStatisticsLogTestingEvent;
+    bool m_downgradeReferrer { true };
 #endif
     UniqueRef<AdClickAttributionManager> m_adClickAttribution;
 
index 43ad6f1..945a52a 100644 (file)
@@ -80,13 +80,13 @@ private:
     bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&);
     void applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(__strong NSURLRequest*&, bool shouldContentSniff, bool shouldContentEncodingSniff);
 
-    void restrictRequestReferrerToOriginIfNeeded(WebCore::ResourceRequest&, bool shouldBlockCookies);
+    void restrictRequestReferrerToOriginIfNeeded(WebCore::ResourceRequest&);
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     static NSHTTPCookieStorage *statelessCookieStorage();
     void blockCookies();
 #endif
-    bool isThirdPartyRequest(const WebCore::ResourceRequest&);
+    bool isThirdPartyRequest(const WebCore::ResourceRequest&) const;
     bool isAlwaysOnLoggingAllowed() const;
 
     RefPtr<SandboxExtension> m_sandboxExtension;
index a4efa9f..77a220f 100644 (file)
@@ -144,7 +144,7 @@ void NetworkDataTaskCocoa::blockCookies()
 }
 #endif
 
-bool NetworkDataTaskCocoa::isThirdPartyRequest(const WebCore::ResourceRequest& request)
+bool NetworkDataTaskCocoa::isThirdPartyRequest(const WebCore::ResourceRequest& request) const
 {
     return !WebCore::areRegistrableDomainsEqual(request.url(), request.firstPartyForCookies());
 }
@@ -216,7 +216,7 @@ NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataT
         needsIsolatedSession = session.shouldIsolateSessionsForPrevalentTopFrames() && networkStorageSession->shouldBlockThirdPartyCookiesButKeepFirstPartyCookiesFor(firstParty);
     }
 #endif
-    restrictRequestReferrerToOriginIfNeeded(request, shouldBlockCookies);
+    restrictRequestReferrerToOriginIfNeeded(request);
 
     NSURLRequest *nsRequest = request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
     applySniffingPoliciesAndBindRequestToInferfaceIfNeeded(nsRequest, shouldContentSniff == WebCore::ContentSniffingPolicy::SniffContent && !url.isLocalFile(), shouldContentEncodingSniff == WebCore::ContentEncodingSniffingPolicy::Sniff);
@@ -297,9 +297,9 @@ NetworkDataTaskCocoa::~NetworkDataTaskCocoa()
     }
 }
 
-void NetworkDataTaskCocoa::restrictRequestReferrerToOriginIfNeeded(WebCore::ResourceRequest& request, bool shouldBlockCookies)
+void NetworkDataTaskCocoa::restrictRequestReferrerToOriginIfNeeded(WebCore::ResourceRequest& request)
 {
-    if (shouldBlockCookies || (m_session->sessionID().isEphemeral() && isThirdPartyRequest(request)))
+    if ((m_session->sessionID().isEphemeral() || m_session->isResourceLoadStatisticsEnabled()) && m_session->shouldDowngradeReferrer() && isThirdPartyRequest(request))
         request.setExistingHTTPReferrerToOriginString();
 }
 
@@ -402,14 +402,8 @@ void NetworkDataTaskCocoa::willPerformHTTPRedirection(WebCore::ResourceResponse&
         m_client->willPerformHTTPRedirection(WTFMove(redirectResponse), WTFMove(request), [completionHandler = WTFMove(completionHandler), this, weakThis = makeWeakPtr(*this)] (auto&& request) mutable {
             if (!weakThis)
                 return completionHandler({ });
-            if (!request.isNull()) {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
-                bool shouldBlockCookies = m_session->networkStorageSession() && m_session->networkStorageSession()->shouldBlockCookies(request, m_frameID, m_pageID);
-#else
-                bool shouldBlockCookies = false;
-#endif
-                restrictRequestReferrerToOriginIfNeeded(request, shouldBlockCookies);
-            }
+            if (!request.isNull())
+                restrictRequestReferrerToOriginIfNeeded(request);
             completionHandler(WTFMove(request));
         });
     else {
index f296b6b..960f9fb 100644 (file)
@@ -502,6 +502,17 @@ void WKWebsiteDataStoreStatisticsHasIsolatedSession(WKWebsiteDataStoreRef dataSt
 #endif
 }
 
+void WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTestingFunction completionHandler)
+{
+#if ENABLE(RESOURCE_LOAD_STATISTICS)
+    WebKit::toImpl(dataStoreRef)->setResourceLoadStatisticsShouldDowngradeReferrerForTesting(enabled, [context, completionHandler] {
+        completionHandler(context);
+    });
+#else
+    completionHandler(context);
+#endif
+}
+
 void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler)
 {
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
@@ -513,6 +524,7 @@ void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef da
     store.clearResourceLoadStatisticsInWebProcesses([callbackAggregator = callbackAggregator.copyRef()] { });
     store.resetCacheMaxAgeCapForPrevalentResources([callbackAggregator = callbackAggregator.copyRef()] { });
     store.resetCrossSiteLoadsWithLinkDecorationForTesting([callbackAggregator = callbackAggregator.copyRef()] { });
+    store.setResourceLoadStatisticsShouldDowngradeReferrerForTesting(true, [callbackAggregator = callbackAggregator.copyRef()] { });
     store.resetParametersToDefaultValues([callbackAggregator = callbackAggregator.copyRef()] { });
     store.scheduleClearInMemoryAndPersistent(WebKit::ShouldGrandfatherStatistics::No, [callbackAggregator = callbackAggregator.copyRef()] { });
 #else
index b8357cc..ccf5913 100644 (file)
@@ -110,6 +110,8 @@ typedef void (*WKWebsiteDataStoreSetStatisticsCacheMaxAgeCapFunction)(void* func
 WK_EXPORT void WKWebsiteDataStoreSetStatisticsCacheMaxAgeCap(WKWebsiteDataStoreRef dataStoreRef, double seconds, void* context, WKWebsiteDataStoreSetStatisticsCacheMaxAgeCapFunction);
 typedef void (*WKWebsiteDataStoreStatisticsHasIsolatedSessionFunction)(bool hasIsolatedSession, void* functionContext);
 WK_EXPORT void WKWebsiteDataStoreStatisticsHasIsolatedSession(WKWebsiteDataStoreRef dataStoreRef, WKStringRef host, void* context, WKWebsiteDataStoreStatisticsHasIsolatedSessionFunction callback);
+typedef void (*WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTestingFunction)(void* functionContext);
+WK_EXPORT void WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTesting(WKWebsiteDataStoreRef dataStoreRef, bool enabled, void* context, WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTestingFunction completionHandler);
 typedef void (*WKWebsiteDataStoreStatisticsResetToConsistentStateFunction)(void* functionContext);
 WK_EXPORT void WKWebsiteDataStoreStatisticsResetToConsistentState(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreStatisticsResetToConsistentStateFunction completionHandler);
 
index b5f69af..02ce8c4 100644 (file)
@@ -1029,6 +1029,15 @@ void NetworkProcessProxy::hasIsolatedSession(PAL::SessionID sessionID, const Reg
     sendWithAsyncReply(Messages::NetworkProcess::HasIsolatedSession(sessionID, domain), WTFMove(completionHandler));
 }
 
+void NetworkProcessProxy::setShouldDowngradeReferrerForTesting(bool enabled, CompletionHandler<void()>&& completionHandler)
+{
+    if (!canSendMessage()) {
+        completionHandler();
+        return;
+    }
+    
+    sendWithAsyncReply(Messages::NetworkProcess::SetShouldDowngradeReferrerForTesting(enabled), WTFMove(completionHandler));
+}
 #endif // ENABLE(RESOURCE_LOAD_STATISTICS)
 
 void NetworkProcessProxy::sendProcessWillSuspendImminently()
index 5eedb70..2fbf3f0 100644 (file)
@@ -152,6 +152,7 @@ public:
     void deleteCookiesForTesting(PAL::SessionID, const RegistrableDomain&, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
     void deleteWebsiteDataInUIProcessForRegistrableDomains(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, Vector<RegistrableDomain>, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&);
     void hasIsolatedSession(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
+    void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
 #endif
 
     void processReadyToSuspend();
index 032ebcb..78e11db 100644 (file)
@@ -1710,6 +1710,20 @@ void WebsiteDataStore::hasIsolatedSessionForTesting(const URL& url, CompletionHa
     }
     ASSERT(!completionHandler);
 }
+
+void WebsiteDataStore::setResourceLoadStatisticsShouldDowngradeReferrerForTesting(bool enabled, CompletionHandler<void()>&& completionHandler)
+{
+    auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
+    
+    for (auto& processPool : processPools()) {
+        if (auto* networkProcess = processPool->networkProcess()) {
+            networkProcess->setShouldDowngradeReferrerForTesting(enabled, [callbackAggregator = callbackAggregator.copyRef()] { });
+            ASSERT(processPools().size() == 1);
+            break;
+        }
+    }
+    ASSERT(!completionHandler);
+}
 #endif // ENABLE(RESOURCE_LOAD_STATISTICS)
 
 void WebsiteDataStore::setCacheMaxAgeCapForPrevalentResources(Seconds seconds, CompletionHandler<void()>&& completionHandler)
index fc1291f..8a5feba 100644 (file)
@@ -187,6 +187,7 @@ public:
     void deleteCookiesForTesting(const URL&, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
     void hasLocalStorageForTesting(const URL&, CompletionHandler<void(bool)>&&) const;
     void hasIsolatedSessionForTesting(const URL&, CompletionHandler<void(bool)>&&) const;
+    void setResourceLoadStatisticsShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
 #endif
     void setCacheMaxAgeCapForPrevalentResources(Seconds, CompletionHandler<void()>&&);
     void resetCacheMaxAgeCapForPrevalentResources(CompletionHandler<void()>&&);
index 16570c9..a541ff5 100644 (file)
@@ -1,3 +1,36 @@
+2019-09-26 Kate Cheney <katherine_cheney@apple.com>
+
+        Resource Load Statistics: Downgrade all third-party referrer headers
+        https://bugs.webkit.org/show_bug.cgi?id=201353
+        <rdar://problem/54895650>
+
+        Majority of this patch was written by John Wilander <wilander@apple.com>.
+
+        Reviewed by Brent Fulgham. 
+
+        The changes to the TestRunner facilitates an opt-out for test cases
+        that either test the referrer mechanism explicitly or tests that
+        rely on the full referrer to be sent. 
+
+        The new boolean variable and early return in 
+        TestRunner::setStatisticsShouldDowngradeReferrer() prevent the same
+        event from trying to set multiple TestRunner callbacks.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::didReceiveMessageToPage):
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setStatisticsShouldDowngradeReferrer):
+        (WTR::TestRunner::statisticsCallDidSetShouldDowngradeReferrerCallback):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::setStatisticsShouldDowngradeReferrer):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+        (WTR::TestInvocation::didSetShouldDowngradeReferrer):
+        * WebKitTestRunner/TestInvocation.h:
+
 2019-09-26  Dean Jackson  <dino@apple.com>
 
         Build fix.
index 9676f2e..6a3981b 100644 (file)
@@ -338,6 +338,7 @@ interface TestRunner {
     void setStatisticsCacheMaxAgeCap(double seconds);
     void statisticsResetToConsistentState(object completionHandler);
     boolean hasStatisticsIsolatedSession(DOMString hostName);
+    void setStatisticsShouldDowngradeReferrer(boolean value, object callback);
 
     // Injected bundle form client.
     void installTextDidChangeInTextFieldCallback(object callback);
index 7339afc..9c10b40 100644 (file)
@@ -327,6 +327,11 @@ void InjectedBundle::didReceiveMessageToPage(WKBundlePageRef page, WKStringRef m
         return;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "CallDidSetShouldDowngradeReferrer")) {
+        m_testRunner->statisticsCallDidSetShouldDowngradeReferrerCallback();
+        return;
+    }
+
     if (WKStringIsEqualToUTF8CString(messageName, "CallDidResetStatisticsToConsistentState")) {
         m_testRunner->statisticsCallDidResetToConsistentStateCallback();
         return;
index cff40f3..3e77f87 100644 (file)
@@ -741,6 +741,7 @@ enum {
     StatisticsDidClearThroughWebsiteDataRemovalCallbackID,
     StatisticsDidResetToConsistentStateCallbackID,
     StatisticsDidSetBlockCookiesForHostCallbackID,
+    StatisticsDidSetShouldDowngradeReferrerCallbackID,
     AllStorageAccessEntriesCallbackID,
     DidRemoveAllSessionCredentialsCallbackID,
     GetApplicationManifestCallbackID,
@@ -2100,6 +2101,23 @@ bool TestRunner::hasStatisticsIsolatedSession(JSStringRef hostName)
     return WKBooleanGetValue(adoptWK(static_cast<WKBooleanRef>(returnData)).get());
 }
 
+void TestRunner::setStatisticsShouldDowngradeReferrer(bool value, JSValueRef completionHandler)
+{
+    if (m_hasSetDowngradeReferrerCallback)
+        return;
+    
+    cacheTestRunnerCallback(StatisticsDidSetShouldDowngradeReferrerCallbackID, completionHandler);
+    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("SetStatisticsShouldDowngradeReferrer"));
+    WKRetainPtr<WKBooleanRef> messageBody = adoptWK(WKBooleanCreate(value));
+    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
+    m_hasSetDowngradeReferrerCallback = true;
+}
+
+void TestRunner::statisticsCallDidSetShouldDowngradeReferrerCallback()
+{
+    callTestRunnerCallback(StatisticsDidSetShouldDowngradeReferrerCallbackID);
+}
+
 void TestRunner::statisticsCallClearThroughWebsiteDataRemovalCallback()
 {
     callTestRunnerCallback(StatisticsDidClearThroughWebsiteDataRemovalCallbackID);
index f4ad3a6..0c93a8f 100644 (file)
@@ -435,6 +435,8 @@ public:
     bool isStatisticsHasLocalStorage(JSStringRef hostName);
     void setStatisticsCacheMaxAgeCap(double seconds);
     bool hasStatisticsIsolatedSession(JSStringRef hostName);
+    void setStatisticsShouldDowngradeReferrer(bool, JSValueRef callback);
+    void statisticsCallDidSetShouldDowngradeReferrerCallback();
     void statisticsResetToConsistentState(JSValueRef completionHandler);
     void statisticsCallDidResetToConsistentStateCallback();
 
@@ -568,6 +570,7 @@ private:
 
     bool m_userStyleSheetEnabled { false };
     bool m_dumpAllHTTPRedirectedResponseHeaders { false };
+    bool m_hasSetDowngradeReferrerCallback { false };
 };
 
 } // namespace WTR
index 2f5bd99..fc6712e 100644 (file)
@@ -3516,6 +3516,14 @@ bool TestController::hasStatisticsIsolatedSession(WKStringRef host)
     return context.result;
 }
 
+void TestController::setStatisticsShouldDowngradeReferrer(bool value)
+{
+    ResourceStatisticsCallbackContext context(*this);
+    WKWebsiteDataStoreSetResourceLoadStatisticsShouldDowngradeReferrerForTesting(TestController::websiteDataStore(), value, &context, resourceStatisticsVoidResultCallback);
+    runUntil(context.done, noTimeout);
+    m_currentInvocation->didSetShouldDowngradeReferrer();
+}
+
 void TestController::statisticsResetToConsistentState()
 {
     ResourceStatisticsCallbackContext context(*this);
index 72edabe..eb71df8 100644 (file)
@@ -249,6 +249,7 @@ public:
     bool isStatisticsHasLocalStorage(WKStringRef hostName);
     void setStatisticsCacheMaxAgeCap(double seconds);
     bool hasStatisticsIsolatedSession(WKStringRef hostName);
+    void setStatisticsShouldDowngradeReferrer(bool value);
     void statisticsResetToConsistentState();
 
     void getAllStorageAccessEntries();
index 30650c4..3e4f2e7 100644 (file)
@@ -1489,6 +1489,13 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
         return result;
     }
     
+    if (WKStringIsEqualToUTF8CString(messageName, "SetStatisticsShouldDowngradeReferrer")) {
+        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
+        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
+        TestController::singleton().setStatisticsShouldDowngradeReferrer(WKBooleanGetValue(value));
+        return nullptr;
+    }
+    
     if (WKStringIsEqualToUTF8CString(messageName, "RemoveAllSessionCredentials")) {
         TestController::singleton().removeAllSessionCredentials();
         return nullptr;
@@ -1770,6 +1777,12 @@ void TestInvocation::didClearStatisticsThroughWebsiteDataRemoval()
     WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
 }
 
+void TestInvocation::didSetShouldDowngradeReferrer()
+{
+    WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidSetShouldDowngradeReferrer"));
+    WKPagePostMessageToInjectedBundle(TestController::singleton().mainWebView()->page(), messageName.get(), 0);
+}
+
 void TestInvocation::didResetStatisticsToConsistentState()
 {
     WKRetainPtr<WKStringRef> messageName = adoptWK(WKStringCreateWithUTF8CString("CallDidResetStatisticsToConsistentState"));
index 85b1b02..76aa9b8 100644 (file)
@@ -73,6 +73,7 @@ public:
     void notifyDownloadDone();
 
     void didClearStatisticsThroughWebsiteDataRemoval();
+    void didSetShouldDowngradeReferrer();
     void didResetStatisticsToConsistentState();
     void didSetBlockCookiesForHost();
     void didSetStatisticsDebugMode();