⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 250589 in webkit


Ignore:
Timestamp:
Oct 1, 2019, 6:18:48 PM (7 years ago)
Author:
wilander@apple.com
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:
Location:
trunk
Files:
3 added
16 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r250570 r250589  
     12019-10-01  John Wilander  <wilander@apple.com>
     2
     3        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
     4        https://bugs.webkit.org/show_bug.cgi?id=202435
     5        <rdar://problem/55718526>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        WebKit's Storage Access API implementation has so far only looked at whether ITP is
     10        blocking cookie access or not. However, the default cookie policy is still in
     11        effect underneath ITP. document.hasStorageAccess() should return true if the
     12        third-party:
     13        a) is not classified by ITP, and
     14        b) has cookies which implies it can use cookies as third-party according to the
     15        default cookie policy.
     16
     17        * http/tests/storageAccess/has-storage-access-false-by-default-ephemeral-expected.txt: Added.
     18        * 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.
     19        * http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral-expected.txt: Added.
     20        * 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.
     21        * http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-expected.txt: Added.
     22        * 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.
     23        * platform/ios/TestExpectations:
     24        * platform/mac-wk2/TestExpectations:
     25
    1262019-10-01  Rob Buis  <rbuis@igalia.com>
    227
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html

    r250588 r250589  
    44<head>
    55    <script src="/js-test-resources/js-test.js"></script>
    6     <script src="/js-test-resources/ui-helper.js"></script>
    76    <script src="/resourceLoadStatistics/resources/util.js"></script>
    87    <script>
    9         description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if there is no way to request access (feature off).");
     8        description("Tests that document.hasStorageAccess() returns false for a 3rd-party iframe by default (ephemeral session).");
    109        jsTestIsAsync = true;
    1110
     
    2019            } else
    2120                testFailed("Received a message from an unexpected origin: " + event.origin);
    22             setEnableFeature(false, finishJSTest);
     21            finishJSTest();
    2322        }
    2423
     
    2625        const statisticsUrl = "http://" + hostUnderTest + "/temp";
    2726        function runTest() {
    28             setEnableFeature(false, function() {
    29                 let iframeElement = document.createElement("iframe");
    30                 iframeElement.id = "TheIframeThatRequestsStorageAccess";
    31                 iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
    32                 document.body.appendChild(iframeElement);
    33             });
     27            let iframeElement = document.createElement("iframe");
     28            iframeElement.id = "TheIframeThatRequestsStorageAccess";
     29            iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldDenyAccess";
     30            document.body.appendChild(iframeElement);
    3431        }
    3532    </script>
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html

    r250588 r250589  
    44<head>
    55    <script src="/js-test-resources/js-test.js"></script>
    6     <script src="/js-test-resources/ui-helper.js"></script>
    76    <script src="/resourceLoadStatistics/resources/util.js"></script>
    87    <script>
    9         description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if there is no way to request access (feature off).");
     8        description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set (ephemeral session).");
    109        jsTestIsAsync = true;
    1110
     
    2019            } else
    2120                testFailed("Received a message from an unexpected origin: " + event.origin);
    22             setEnableFeature(false, finishJSTest);
     21            finishJSTest();
    2322        }
    2423
    2524        const hostUnderTest = "localhost:8000";
    26         const statisticsUrl = "http://" + hostUnderTest + "/temp";
     25        const statisticsUrl = "http://" + hostUnderTest;
    2726        function runTest() {
    28             setEnableFeature(false, function() {
     27            if (document.location.hash !== "#firstPartyCookieSet") {
     28                document.location.href = statisticsUrl + "/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";
     29            } else {
    2930                let iframeElement = document.createElement("iframe");
    3031                iframeElement.id = "TheIframeThatRequestsStorageAccess";
    3132                iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
    3233                document.body.appendChild(iframeElement);
    33             });
     34            }
    3435        }
    3536    </script>
  • trunk/LayoutTests/http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html

    r250588 r250589  
    44<head>
    55    <script src="/js-test-resources/js-test.js"></script>
    6     <script src="/js-test-resources/ui-helper.js"></script>
    76    <script src="/resourceLoadStatistics/resources/util.js"></script>
    87    <script>
    9         description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if there is no way to request access (feature off).");
     8        description("Tests that document.hasStorageAccess() returns true for a 3rd-party iframe if the 3rd-party has cookies set.");
    109        jsTestIsAsync = true;
    1110
     
    2423
    2524        const hostUnderTest = "localhost:8000";
    26         const statisticsUrl = "http://" + hostUnderTest + "/temp";
     25        const statisticsUrl = "http://" + hostUnderTest;
    2726        function runTest() {
    28             setEnableFeature(false, function() {
     27            if (document.location.hash !== "#firstPartyCookieSet") {
     28                setEnableFeature(false, function() {
     29                    document.location.href = statisticsUrl + "/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";
     30                });
     31            } else {
    2932                let iframeElement = document.createElement("iframe");
    3033                iframeElement.id = "TheIframeThatRequestsStorageAccess";
    3134                iframeElement.src = "http://localhost:8000/storageAccess/resources/has-storage-access-iframe.html#policyShouldGrantAccess";
    3235                document.body.appendChild(iframeElement);
    33             });
     36            }
    3437        }
    3538    </script>
  • trunk/LayoutTests/platform/ios/TestExpectations

    r250450 r250589  
    28002800http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource.html [ Pass ]
    28012801http/tests/storageAccess/has-storage-access-false-by-default.html [ Pass ]
    2802 
     2802http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html [ Pass ]
     2803http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html [ Pass ]
     2804http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html [ Pass ]
    28032805
    28042806# Skipped in general expectations since they only work on iOS and Mac, WK2.
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r250431 r250589  
    712712[ HighSierra+ ] http/tests/storageAccess/deny-with-prompt-does-not-preserve-gesture.html [ Skip ]
    713713[ HighSierra+ ] http/tests/storageAccess/deny-without-prompt-preserves-gesture.html [ Pass ]
    714 [ HighSierra+ ] http/tests/storageAccess/has-storage-access-true-if-feature-off.html [ Pass ]
    715714[ HighSierra+ ] http/tests/storageAccess/has-storage-access-false-by-default.html [ Pass ]
     715[ HighSierra+ ] http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html [ Pass ]
     716[ HighSierra+ ] http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html [ Pass ]
     717[ HighSierra+ ] http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html [ Pass ]
    716718
    717719# As of https://trac.webkit.org/changeset/227762 the timestampResolution is just 5 seconds which makes this test flaky
  • trunk/Source/WebCore/ChangeLog

    r250588 r250589  
     12019-10-01  John Wilander  <wilander@apple.com>
     2
     3        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
     4        https://bugs.webkit.org/show_bug.cgi?id=202435
     5        <rdar://problem/55718526>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        WebKit's Storage Access API implementation has so far only looked at whether ITP is
     10        blocking cookie access or not. However, the default cookie policy is still in
     11        effect underneath ITP. document.hasStorageAccess() should return true if the
     12        third-party:
     13        a) is not classified by ITP, and
     14        b) has cookies which implies it can use cookies as third-party according to the
     15        default cookie policy.
     16
     17        Tests: http/tests/storageAccess/has-storage-access-false-by-default-ephemeral.html
     18               http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies-ephemeral.html
     19               http/tests/storageAccess/has-storage-access-true-if-third-party-has-cookies.html
     20
     21        * platform/network/NetworkStorageSession.h:
     22        * platform/network/cocoa/NetworkStorageSessionCocoa.mm:
     23        (WebCore::NetworkStorageSession::hasCookies const):
     24        * platform/network/curl/NetworkStorageSessionCurl.cpp:
     25        (WebCore::NetworkStorageSession::hasCookies const):
     26            Not yet implemented. Always says false.
     27        * platform/network/soup/NetworkStorageSessionSoup.cpp:
     28        (WebCore::NetworkStorageSession::hasCookies const):
     29            Not yet implemented. Always says false.
     30
    1312019-10-01  Tim Horton  <timothy_horton@apple.com>
    232
  • trunk/Source/WebCore/platform/network/NetworkStorageSession.h

    r248902 r250589  
    3131#include "RegistrableDomain.h"
    3232#include <pal/SessionID.h>
     33#include <wtf/CompletionHandler.h>
    3334#include <wtf/Function.h>
    3435#include <wtf/HashMap.h>
     
    134135    WEBCORE_EXPORT Vector<Cookie> getAllCookies();
    135136    WEBCORE_EXPORT Vector<Cookie> getCookies(const URL&);
     137    WEBCORE_EXPORT void hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
    136138    WEBCORE_EXPORT bool getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL&, Optional<FrameIdentifier>, Optional<PageIdentifier>, Vector<Cookie>&) const;
    137139    WEBCORE_EXPORT void flushCookieStore();
  • trunk/Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm

    r248902 r250589  
    103103}
    104104
     105void NetworkStorageSession::hasCookies(const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler) const
     106{
     107    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
     108   
     109    for (NSHTTPCookie *nsCookie in nsCookieStorage().cookies) {
     110        if (RegistrableDomain::uncheckedCreateFromHost(nsCookie.domain) == domain) {
     111            completionHandler(true);
     112            return;
     113        }
     114    }
     115
     116    completionHandler(false);
     117}
     118
    105119void NetworkStorageSession::flushCookieStore()
    106120{
  • trunk/Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp

    r248714 r250589  
    155155}
    156156
     157void NetworkStorageSession::hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&& completionHandler) const
     158{
     159    // FIXME: Implement.
     160    completionHandler(false);
     161}
     162
    157163bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, Vector<Cookie>& rawCookies) const
    158164{
  • trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp

    r248846 r250589  
    415415}
    416416
     417void NetworkStorageSession::hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&& completionHandler) const
     418{
     419    // FIXME: Implement.
     420    completionHandler(false);
     421}
     422
    417423bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, Vector<Cookie>& rawCookies) const
    418424{
  • trunk/Source/WebKit/ChangeLog

    r250584 r250589  
     12019-10-01  John Wilander  <wilander@apple.com>
     2
     3        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
     4        https://bugs.webkit.org/show_bug.cgi?id=202435
     5        <rdar://problem/55718526>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        WebKit's Storage Access API implementation has so far only looked at whether ITP is
     10        blocking cookie access or not. However, the default cookie policy is still in
     11        effect underneath ITP. document.hasStorageAccess() should return true if the
     12        third-party:
     13        a) is not classified by ITP, and
     14        b) has cookies which implies it can use cookies as third-party according to the
     15        default cookie policy.
     16
     17        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
     18        (WebKit::ResourceLoadStatisticsMemoryStore::hasStorageAccess):
     19        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     20        (WebKit::WebResourceLoadStatisticsStore::hasCookies):
     21        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
     22        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     23        (WebKit::NetworkConnectionToWebProcess::hasStorageAccess):
     24        * NetworkProcess/NetworkProcess.cpp:
     25        (WebKit::NetworkProcess::registrableDomainsWithWebsiteData):
     26
    1272019-10-01  Antti Koivisto  <antti@apple.com>
    228
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp

    r250431 r250589  
    218218    auto& subFrameStatistic = ensureResourceStatisticsForRegistrableDomain(subFrameDomain);
    219219    // Return false if this domain cannot ask for storage access.
    220     if (shouldBlockAndPurgeCookies(subFrameStatistic) || !shouldBlockAndKeepCookies(subFrameStatistic)) {
     220    if (shouldBlockAndPurgeCookies(subFrameStatistic)) {
    221221        completionHandler(false);
     222        return;
     223    }
     224
     225    if (!shouldBlockAndKeepCookies(subFrameStatistic)) {
     226        RunLoop::main().dispatch([store = makeRef(store()), subFrameDomain = subFrameDomain.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
     227            store->hasCookies(subFrameDomain, [store = store.copyRef(), completionHandler = WTFMove(completionHandler)](bool result) mutable {
     228                store->statisticsQueue().dispatch([completionHandler = WTFMove(completionHandler), result] () mutable {
     229                    completionHandler(result);
     230                });
     231            });
     232        });
    222233        return;
    223234    }
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r250393 r250589  
    435435}
    436436
     437void WebResourceLoadStatisticsStore::hasCookies(const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler)
     438{
     439    ASSERT(RunLoop::isMain());
     440
     441    if (m_networkSession) {
     442        if (auto* storageSession = m_networkSession->networkStorageSession()) {
     443            storageSession->hasCookies(domain, WTFMove(completionHandler));
     444            return;
     445        }
     446    }
     447   
     448    completionHandler(false);
     449}
     450
    437451void WebResourceLoadStatisticsStore::didCreateNetworkProcess()
    438452{
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h

    r249920 r250589  
    177177    void callHasStorageAccessForFrameHandler(const SubFrameDomain&, const TopFrameDomain&, WebCore::FrameIdentifier, WebCore::PageIdentifier, CompletionHandler<void(bool)>&&);
    178178
     179    void hasCookies(const RegistrableDomain&, CompletionHandler<void(bool)>&&);
     180
    179181    void didCreateNetworkProcess();
    180182
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r250354 r250589  
    717717            resourceLoadStatistics->hasStorageAccess(subFrameDomain, topFrameDomain, frameID, pageID, WTFMove(completionHandler));
    718718            return;
     719        } else {
     720            storageSession()->hasCookies(subFrameDomain, WTFMove(completionHandler));
     721            return;
    719722        }
    720723    }
    721724
    722     completionHandler(true);
     725    completionHandler(false);
    723726}
    724727
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r250521 r250589  
    18391839    auto& websiteDataStore = callbackAggregator->m_websiteData;
    18401840   
    1841     Vector<String> hostnamesWithCookiesToDelete;
    18421841    if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
    18431842        if (auto* networkStorageSession = storageSession(sessionID))
     
    18451844    }
    18461845   
    1847     Vector<String> hostnamesWithHSTSToDelete;
    18481846#if PLATFORM(COCOA) || USE(SOUP)
    18491847    if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
  • trunk/Tools/ChangeLog

    r250587 r250589  
     12019-10-01  John Wilander  <wilander@apple.com>
     2
     3        Storage Access API: document.hasStorageAccess() should return true when the cookie policy allows access
     4        https://bugs.webkit.org/show_bug.cgi?id=202435
     5        <rdar://problem/55718526>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This change makes sure topPrivatelyControlledDomain() correctly handles domains
     10        with leading dots, as often used in cookie domains.
     11
     12        * TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp:
     13        (TestWebKitAPI::TEST_F):
     14
    1152019-10-01  Jonathan Bedard  <jbedard@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp

    r237584 r250589  
    180180    EXPECT_EQ(String("åäö"), topPrivatelyControlledDomain("åäö"));
    181181    EXPECT_EQ(String("ÅÄÖ"), topPrivatelyControlledDomain("ÅÄÖ"));
     182    EXPECT_EQ(String("test.com"), topPrivatelyControlledDomain(".test.com"));
    182183}
    183184
Note: See TracChangeset for help on using the changeset viewer.