Title: [250589] trunk
Revision
250589
Author
wilan...@apple.com
Date
2019-10-01 18:18:48 -0700 (Tue, 01 Oct 2019)

Log Message

Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
https://bugs.webkit.org/show_bug.cgi?id=202435
<rdar://problem/55718526>

Reviewed by Brent Fulgham.

Source/WebCore:

WebKit's Storage Access API implementation has so far only looked at whether ITP is
blocking cookie access or not. However, the default cookie policy is still in
effect underneath ITP. document.hasStorageAccess() should return true if the
third-party:
a) is not classified by ITP, and
b) has cookies which implies it can use cookies as third-party according to the
default cookie policy.

Tests: http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html
       http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html
       http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html

* platform/network/NetworkStorageSession.h:
* platform/network/cocoa/NetworkStorageSessionCocoa.mm:
(WebCore::NetworkStorageSession::hasCookies const):
* platform/network/curl/NetworkStorageSessionCurl.cpp:
(WebCore::NetworkStorageSession::hasCookies const):
    Not yet implemented. Always says false.
* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::hasCookies const):
    Not yet implemented. Always says false.

Source/WebKit:

WebKit's Storage Access API implementation has so far only looked at whether ITP is
blocking cookie access or not. However, the default cookie policy is still in
effect underneath ITP. document.hasStorageAccess() should return true if the
third-party:
a) is not classified by ITP, and
b) has cookies which implies it can use cookies as third-party according to the
default cookie policy.

* NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
(WebKit::ResourceLoadStatisticsMemoryStore::hasStorageAccess):
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::hasCookies):
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::hasStorageAccess):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::registrableDomainsWithWebsiteData):

Tools:

This change makes sure topPrivatelyControlledDomain() correctly handles domains
with leading dots, as often used in cookie domains.

* TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp:
(TestWebKitAPI::TEST_F):

LayoutTests:

WebKit's Storage Access API implementation has so far only looked at whether ITP is
blocking cookie access or not. However, the default cookie policy is still in
effect underneath ITP. document.hasStorageAccess() should return true if the
third-party:
a) is not classified by ITP, and
b) has cookies which implies it can use cookies as third-party according to the
default cookie policy.

* http/tests/storageAccess/has-storage-access-false-by-default-ephemeral-expected.txt: Added.
* http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html: Copied from LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html.
* http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral-expected.txt: Added.
* http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html: Copied from LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html.
* http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-expected.txt: Added.
* http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html: Renamed from LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html.
* platform/ios/TestExpectations:
* platform/mac-wk2/TestExpectations:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (250588 => 250589)


--- trunk/LayoutTests/ChangeLog	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/LayoutTests/ChangeLog	2019-10-02 01:18:48 UTC (rev 250589)
@@ -1,3 +1,28 @@
+2019-10-01  John Wilander  <wilan...@apple.com>
+
+        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
+        https://bugs.webkit.org/show_bug.cgi?id=202435
+        <rdar://problem/55718526>
+
+        Reviewed by Brent Fulgham.
+
+        WebKit's Storage Access API implementation has so far only looked at whether ITP is
+        blocking cookie access or not. However, the default cookie policy is still in
+        effect underneath ITP. document.hasStorageAccess() should return true if the
+        third-party:
+        a) is not classified by ITP, and
+        b) has cookies which implies it can use cookies as third-party according to the
+        default cookie policy.
+
+        * http/tests/storageAccess/has-storage-access-false-by-default-ephemeral-expected.txt: Added.
+        * http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html: Copied from LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html.
+        * http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral-expected.txt: Added.
+        * http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html: Copied from LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html.
+        * http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-expected.txt: Added.
+        * http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html: Renamed from LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html.
+        * platform/ios/TestExpectations:
+        * platform/mac-wk2/TestExpectations:
+
 2019-10-01  Rob Buis  <rb...@igalia.com>
 
         [Mac] Layout Test imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location.any.html fails

Added: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral-expected.txt (0 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral-expected.txt	2019-10-02 01:18:48 UTC (rev 250589)
@@ -0,0 +1,10 @@
+Tests that document.hasStorageAccess() returns false for a 3rd-party iframe by default (ephemeral session).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS No storage access. document.cookie == , cookies seen server-side == "No cookies"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Copied: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html (from rev 250588, trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html) (0 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html	2019-10-02 01:18:48 UTC (rev 250589)
@@ -0,0 +1,36 @@
+<!-- webkit-test-runner [ useEphemeralSession=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script>
+        description("Tests that document.hasStorageAccess() returns false for a 3rd-party iframe by default (ephemeral session).");
+        jsTestIsAsync = true;
+
+        window.addEventListener("message", receiveMessage, false);
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS") !== -1)
+                    testPassed(event.data.replace("PASS ", ""));
+                else
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+            finishJSTest();
+        }
+
+        const hostUnderTest = "localhost:8000";
+        const statisticsUrl = "http://" + hostUnderTest + "/temp";
+        function runTest() {
+            let iframeElement = document.createElement("iframe");
+            iframeElement.id = "TheIframeThatRequestsStorageAccess";
+            iframeElement.src = ""
+            document.body.appendChild(iframeElement);
+        }
+    </script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Deleted: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html (250588 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html	2019-10-02 01:18:48 UTC (rev 250589)
@@ -1,39 +0,0 @@
-<!-- webkit-test-runner [ useEphemeralSession=true ] -->
-<!DOCTYPE html>
-<html>
-<head>
-    <script src=""
-    <script src=""
-    <script src=""
-    <script>
-        description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if there is no way to request access (feature off).");
-        jsTestIsAsync = true;
-
-        window.addEventListener("message", receiveMessage, false);
-
-        function receiveMessage(event) {
-            if (event.origin === "http://localhost:8000") {
-                if (event.data.indexOf("PASS") !== -1)
-                    testPassed(event.data.replace("PASS ", ""));
-                else
-                    testFailed(event.data.replace("FAIL ", ""));
-            } else
-                testFailed("Received a message from an unexpected origin: " + event.origin);
-            setEnableFeature(false, finishJSTest);
-        }
-
-        const hostUnderTest = "localhost:8000";
-        const statisticsUrl = "http://" + hostUnderTest + "/temp";
-        function runTest() {
-            setEnableFeature(false, function() {
-                let iframeElement = document.createElement("iframe");
-                iframeElement.id = "TheIframeThatRequestsStorageAccess";
-                iframeElement.src = ""
-                document.body.appendChild(iframeElement);
-            });
-        }
-    </script>
-</head>
-<body _onload_="runTest()">
-</body>
-</html>

Added: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral-expected.txt (0 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral-expected.txt	2019-10-02 01:18:48 UTC (rev 250589)
@@ -0,0 +1,10 @@
+Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Has storage access. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Copied: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html (from rev 250588, trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html) (0 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html	2019-10-02 01:18:48 UTC (rev 250589)
@@ -0,0 +1,40 @@
+<!-- webkit-test-runner [ useEphemeralSession=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script>
+        description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set (ephemeral session).");
+        jsTestIsAsync = true;
+
+        window.addEventListener("message", receiveMessage, false);
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS") !== -1)
+                    testPassed(event.data.replace("PASS ", ""));
+                else
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+            finishJSTest();
+        }
+
+        const hostUnderTest = "localhost:8000";
+        const statisticsUrl = "http://" + hostUnderTest;
+        function runTest() {
+            if (document.location.hash !== "#firstPartyCookieSet") {
+                document.location.href = "" + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#http://127.0.0.1:8000/storageAccess/has-storage-access-true-if-third-party-has-cookies.html#firstPartyCookieSet";
+            } else {
+                let iframeElement = document.createElement("iframe");
+                iframeElement.id = "TheIframeThatRequestsStorageAccess";
+                iframeElement.src = ""
+                document.body.appendChild(iframeElement);
+            }
+        }
+    </script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-expected.txt (0 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-expected.txt	2019-10-02 01:18:48 UTC (rev 250589)
@@ -0,0 +1,10 @@
+Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Has storage access. document.cookie == firstPartyCookie=value, cookies seen server-side == {"firstPartyCookie":"value"}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Copied: trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html (from rev 250588, trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-feature-off.html) (0 => 250589)


--- trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html	2019-10-02 01:18:48 UTC (rev 250589)
@@ -0,0 +1,42 @@
+<!-- webkit-test-runner [ useEphemeralSession=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <script>
+        description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set.");
+        jsTestIsAsync = true;
+
+        window.addEventListener("message", receiveMessage, false);
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS") !== -1)
+                    testPassed(event.data.replace("PASS ", ""));
+                else
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+            setEnableFeature(false, finishJSTest);
+        }
+
+        const hostUnderTest = "localhost:8000";
+        const statisticsUrl = "http://" + hostUnderTest;
+        function runTest() {
+            if (document.location.hash !== "#firstPartyCookieSet") {
+                setEnableFeature(false, function() {
+                    document.location.href = "" + "/storageAccess/resources/set-cookie.php?name=firstPartyCookie&value=value#http://127.0.0.1:8000/storageAccess/has-storage-access-true-if-third-party-has-cookies.html#firstPartyCookieSet";
+                });
+            } else {
+                let iframeElement = document.createElement("iframe");
+                iframeElement.id = "TheIframeThatRequestsStorageAccess";
+                iframeElement.src = ""
+                document.body.appendChild(iframeElement);
+            }
+        }
+    </script>
+</head>
+<body _onload_="runTest()">
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (250588 => 250589)


--- trunk/LayoutTests/platform/ios/TestExpectations	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2019-10-02 01:18:48 UTC (rev 250589)
@@ -2799,8 +2799,10 @@
 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 ]
 http/tests/storageAccess/has-storage-access-false-by-default.html [ Pass ]
+http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html [ Pass ]
+http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html [ Pass ]
+http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.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 ]

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (250588 => 250589)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2019-10-02 01:18:48 UTC (rev 250589)
@@ -711,8 +711,10 @@
 [ HighSierra+ ] http/tests/storageAccess/grant-with-prompt-preserves-gesture.html [ Pass ]
 [ HighSierra+ ] http/tests/storageAccess/deny-with-prompt-does-not-preserve-gesture.html [ Skip ]
 [ HighSierra+ ] http/tests/storageAccess/deny-without-prompt-preserves-gesture.html [ Pass ]
-[ HighSierra+ ] http/tests/storageAccess/has-storage-access-true-if-feature-off.html [ Pass ]
 [ HighSierra+ ] http/tests/storageAccess/has-storage-access-false-by-default.html [ Pass ]
+[ HighSierra+ ] http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html [ Pass ]
+[ HighSierra+ ] http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html [ Pass ]
+[ HighSierra+ ] http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html [ Pass ]
 
 # As of https://trac.webkit.org/changeset/227762 the timestampResolution is just 5 seconds which makes this test flaky
 http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (250588 => 250589)


--- trunk/Source/WebCore/ChangeLog	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebCore/ChangeLog	2019-10-02 01:18:48 UTC (rev 250589)
@@ -1,3 +1,33 @@
+2019-10-01  John Wilander  <wilan...@apple.com>
+
+        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
+        https://bugs.webkit.org/show_bug.cgi?id=202435
+        <rdar://problem/55718526>
+
+        Reviewed by Brent Fulgham.
+
+        WebKit's Storage Access API implementation has so far only looked at whether ITP is
+        blocking cookie access or not. However, the default cookie policy is still in
+        effect underneath ITP. document.hasStorageAccess() should return true if the
+        third-party:
+        a) is not classified by ITP, and
+        b) has cookies which implies it can use cookies as third-party according to the
+        default cookie policy.
+
+        Tests: http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html
+               http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html
+               http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html
+
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
+        (WebCore::NetworkStorageSession::hasCookies const):
+        * platform/network/curl/NetworkStorageSessionCurl.cpp:
+        (WebCore::NetworkStorageSession::hasCookies const):
+            Not yet implemented. Always says false.
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::hasCookies const):
+            Not yet implemented. Always says false.
+
 2019-10-01  Tim Horton  <timothy_hor...@apple.com>
 
         Clean up some includes to make the build a bit faster

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (250588 => 250589)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2019-10-02 01:18:48 UTC (rev 250589)
@@ -30,6 +30,7 @@
 #include "PageIdentifier.h"
 #include "RegistrableDomain.h"
 #include <pal/SessionID.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/Function.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
@@ -133,6 +134,7 @@
     WEBCORE_EXPORT void deleteCookiesForHostnames(const Vector<String>& cookieHostNames, IncludeHttpOnlyCookies);
     WEBCORE_EXPORT Vector<Cookie> getAllCookies();
     WEBCORE_EXPORT Vector<Cookie> getCookies(const URL&);
+    WEBCORE_EXPORT void hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
     WEBCORE_EXPORT bool getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL&, Optional<FrameIdentifier>, Optional<PageIdentifier>, Vector<Cookie>&) const;
     WEBCORE_EXPORT void flushCookieStore();
     WEBCORE_EXPORT void getHostnamesWithCookies(HashSet<String>& hostnames);

Modified: trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm (250588 => 250589)


--- trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm	2019-10-02 01:18:48 UTC (rev 250589)
@@ -102,6 +102,20 @@
     return nsCookiesToCookieVector([nsCookieStorage() cookiesForURL:(NSURL *)url]);
 }
 
+void NetworkStorageSession::hasCookies(const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler) const
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    
+    for (NSHTTPCookie *nsCookie in nsCookieStorage().cookies) {
+        if (RegistrableDomain::uncheckedCreateFromHost(nsCookie.domain) == domain) {
+            completionHandler(true);
+            return;
+        }
+    }
+
+    completionHandler(false);
+}
+
 void NetworkStorageSession::flushCookieStore()
 {
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));

Modified: trunk/Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp (250588 => 250589)


--- trunk/Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -154,6 +154,12 @@
     return { };
 }
 
+void NetworkStorageSession::hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&& completionHandler) const
+{
+    // FIXME: Implement.
+    completionHandler(false);
+}
+
 bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, Vector<Cookie>& rawCookies) const
 {
     return cookieStorage().getRawCookies(*this, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);

Modified: trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp (250588 => 250589)


--- trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -414,6 +414,12 @@
     return cookies;
 }
 
+void NetworkStorageSession::hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&& completionHandler) const
+{
+    // FIXME: Implement.
+    completionHandler(false);
+}
+
 bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, Vector<Cookie>& rawCookies) const
 {
     UNUSED_PARAM(firstParty);

Modified: trunk/Source/WebKit/ChangeLog (250588 => 250589)


--- trunk/Source/WebKit/ChangeLog	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebKit/ChangeLog	2019-10-02 01:18:48 UTC (rev 250589)
@@ -1,3 +1,29 @@
+2019-10-01  John Wilander  <wilan...@apple.com>
+
+        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
+        https://bugs.webkit.org/show_bug.cgi?id=202435
+        <rdar://problem/55718526>
+
+        Reviewed by Brent Fulgham.
+
+        WebKit's Storage Access API implementation has so far only looked at whether ITP is
+        blocking cookie access or not. However, the default cookie policy is still in
+        effect underneath ITP. document.hasStorageAccess() should return true if the
+        third-party:
+        a) is not classified by ITP, and
+        b) has cookies which implies it can use cookies as third-party according to the
+        default cookie policy.
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
+        (WebKit::ResourceLoadStatisticsMemoryStore::hasStorageAccess):
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::hasCookies):
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::hasStorageAccess):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
+
 2019-10-01  Antti Koivisto  <an...@apple.com>
 
         [CSS Shadow Parts] Parse 'part' attribute

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp (250588 => 250589)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -217,11 +217,22 @@
 
     auto& subFrameStatistic = ensureResourceStatisticsForRegistrableDomain(subFrameDomain);
     // Return false if this domain cannot ask for storage access.
-    if (shouldBlockAndPurgeCookies(subFrameStatistic) || !shouldBlockAndKeepCookies(subFrameStatistic)) {
+    if (shouldBlockAndPurgeCookies(subFrameStatistic)) {
         completionHandler(false);
         return;
     }
 
+    if (!shouldBlockAndKeepCookies(subFrameStatistic)) {
+        RunLoop::main().dispatch([store = makeRef(store()), subFrameDomain = subFrameDomain.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
+            store->hasCookies(subFrameDomain, [store = store.copyRef(), completionHandler = WTFMove(completionHandler)](bool result) mutable {
+                store->statisticsQueue().dispatch([completionHandler = WTFMove(completionHandler), result] () mutable {
+                    completionHandler(result);
+                });
+            });
+        });
+        return;
+    }
+
     RunLoop::main().dispatch([store = makeRef(store()), subFrameDomain = subFrameDomain.isolatedCopy(), topFrameDomain = topFrameDomain.isolatedCopy(), frameID, pageID, completionHandler = WTFMove(completionHandler)]() mutable {
         store->callHasStorageAccessForFrameHandler(subFrameDomain, topFrameDomain, frameID.value(), pageID, [store = store.copyRef(), completionHandler = WTFMove(completionHandler)](bool result) mutable {
             store->statisticsQueue().dispatch([completionHandler = WTFMove(completionHandler), result] () mutable {

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp (250588 => 250589)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -434,6 +434,20 @@
     completionHandler(grantStorageAccess(subFrameDomain, topFrameDomain, frameID, pageID));
 }
 
+void WebResourceLoadStatisticsStore::hasCookies(const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler)
+{
+    ASSERT(RunLoop::isMain());
+
+    if (m_networkSession) {
+        if (auto* storageSession = m_networkSession->networkStorageSession()) {
+            storageSession->hasCookies(domain, WTFMove(completionHandler));
+            return;
+        }
+    }
+    
+    completionHandler(false);
+}
+
 void WebResourceLoadStatisticsStore::didCreateNetworkProcess()
 {
     ASSERT(RunLoop::isMain());

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h (250588 => 250589)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h	2019-10-02 01:18:48 UTC (rev 250589)
@@ -176,6 +176,8 @@
     void callRemoveDomainsHandler(const Vector<RegistrableDomain>&);
     void callHasStorageAccessForFrameHandler(const SubFrameDomain&, const TopFrameDomain&, WebCore::FrameIdentifier, WebCore::PageIdentifier, CompletionHandler<void(bool)>&&);
 
+    void hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&&);
+
     void didCreateNetworkProcess();
 
     void notifyResourceLoadStatisticsProcessed();

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (250588 => 250589)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -716,10 +716,13 @@
         if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) {
             resourceLoadStatistics->hasStorageAccess(subFrameDomain, topFrameDomain, frameID, pageID, WTFMove(completionHandler));
             return;
+        } else {
+            storageSession()->hasCookies(subFrameDomain, WTFMove(completionHandler));
+            return;
         }
     }
 
-    completionHandler(true);
+    completionHandler(false);
 }
 
 void NetworkConnectionToWebProcess::requestStorageAccess(const RegistrableDomain& subFrameDomain, const RegistrableDomain& topFrameDomain, FrameIdentifier frameID, PageIdentifier webPageID, WebPageProxyIdentifier webPageProxyID, CompletionHandler<void(WebCore::StorageAccessWasGranted wasGranted, WebCore::StorageAccessPromptWasShown promptWasShown)>&& completionHandler)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (250588 => 250589)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -1838,13 +1838,11 @@
     
     auto& websiteDataStore = callbackAggregator->m_websiteData;
     
-    Vector<String> hostnamesWithCookiesToDelete;
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
         if (auto* networkStorageSession = storageSession(sessionID))
             networkStorageSession->getHostnamesWithCookies(websiteDataStore.hostNamesWithCookies);
     }
     
-    Vector<String> hostnamesWithHSTSToDelete;
 #if PLATFORM(COCOA) || USE(SOUP)
     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
         if (auto* networkStorageSession = storageSession(sessionID))

Modified: trunk/Tools/ChangeLog (250588 => 250589)


--- trunk/Tools/ChangeLog	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Tools/ChangeLog	2019-10-02 01:18:48 UTC (rev 250589)
@@ -1,3 +1,17 @@
+2019-10-01  John Wilander  <wilan...@apple.com>
+
+        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
+        https://bugs.webkit.org/show_bug.cgi?id=202435
+        <rdar://problem/55718526>
+
+        Reviewed by Brent Fulgham.
+
+        This change makes sure topPrivatelyControlledDomain() correctly handles domains
+        with leading dots, as often used in cookie domains.
+
+        * TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2019-10-01  Jonathan Bedard  <jbed...@apple.com>
 
         results.webkit.org: Standardize styles in the drawer

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp (250588 => 250589)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp	2019-10-02 00:06:58 UTC (rev 250588)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp	2019-10-02 01:18:48 UTC (rev 250589)
@@ -179,6 +179,7 @@
     EXPECT_EQ(String("localhost"), topPrivatelyControlledDomain("LocalHost"));
     EXPECT_EQ(String("åäö"), topPrivatelyControlledDomain("åäö"));
     EXPECT_EQ(String("ÅÄÖ"), topPrivatelyControlledDomain("ÅÄÖ"));
+    EXPECT_EQ(String("test.com"), topPrivatelyControlledDomain(".test.com"));
 }
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to