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

Changeset 283274 in webkit


Ignore:
Timestamp:
Sep 29, 2021, 4:08:05 PM (5 years ago)
Author:
Chris Dumez
Message:

Use isolated NSURLSessions for each first party registrable domain
https://bugs.webkit.org/show_bug.cgi?id=230750
<rdar://83159358>

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT test that is now passing more checks.

  • web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt:

Source/WebCore:

Fix bug where service worker soft-update requests would have their "first-party-for-cookies"
field set to "https:" instead of a full origin (e.g. "https://localhost:8080"). This was
causing some service worker test failures now that we use different NSURLSession based on
the "first-party-for-cookies" field.

  • workers/service/server/SWServer.cpp:

(WebCore::originURL):

Source/WebKit:

Previously would use up to 10 isolated NSURLSessions only for domains marked as prevalent
by ITP *and* that the user interacts with as first party website. We now use different
isolated NSURLSession for each top-level registrable domain, not matter their ITP status.
This significantly improves privacy.

To avoid having too many NSURLSession, we clear the ones that haven't been used in the
last 10 minutes, every time we add a new one.

  • NetworkProcess/cocoa/NetworkSessionCocoa.h:
  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(WebKit::NetworkSessionCocoa::sessionWrapperForTask):
(WebKit::SessionSet::isolatedSession):

LayoutTests:

This test is now passing more checks on WebKit2 but still completely fails on WebKit1 so I am
adding a WK1-specific baseline.

  • platform/mac-wk1/imported/w3c/web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt.
Location:
trunk
Files:
1 added
2 deleted
10 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r283269 r283274  
     12021-09-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Use isolated NSURLSessions for each first party registrable domain
     4        https://bugs.webkit.org/show_bug.cgi?id=230750
     5        <rdar://83159358>
     6
     7        Reviewed by Alex Christensen.
     8
     9        This test is now passing more checks on WebKit2 but still completely fails on WebKit1 so I am
     10        adding a WK1-specific baseline.
     11
     12        * platform/mac-wk1/imported/w3c/web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt.
     13
    1142021-09-29  Aditya Keerthi  <akeerthi@apple.com>
    215
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-without-interaction-expected.txt

    r283273 r283274  
    1 Tests that the session is switched upon top frame navigation to a prevalent resource with user interaction.
     1Tests that the session is switched upon top frame navigation to a prevalent resource without user interaction.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
  • trunk/LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-without-interaction.py

    r283273 r283274  
    1717<body onload="runTest()">
    1818<script>
    19     description("Tests that the session is not switched upon top frame navigation to a prevalent resource without user interaction.");
     19    description("Tests that the session is switched upon top frame navigation to a prevalent resource without user interaction.");
    2020    jsTestIsAsync = true;
    2121
     
    7474                    runTest();
    7575                });
     76                break;
    7677            case "#step1":
    7778                setSessionCookie();
    7879                setPersistentCookie();
    7980                checkCookies(true, true);
    80                 if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin)) {
    81                     testFailed("Origin has isolated session.");
     81                if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin))
     82                    testPassed("Origin has isolated session.");
     83                else {
     84                    testFailed("Origin has no isolated session.");
    8285                    setEnableFeature(false, finishJSTest);
    83                 } else
    84                     testPassed("Origin has no isolated session.");
    85                 document.location.href = nonPrevalentOrigin + "/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction.py#step2";
     86                }
     87                document.location.href = nonPrevalentOrigin + "/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-without-interaction.py#step2";
    8688                break;
    8789            case "#step2":
     
    98100                break;
    99101            case "#step3":
    100                 document.location.href = prevalentOrigin + "/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction.py#step4";
     102                document.location.href = prevalentOrigin + "/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-without-interaction.py#step4";
    101103                break;
    102104            case "#step4":
    103105                checkCookies(true, true);
    104106                if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin))
    105                     testFailed("Origin has isolated session.");
     107                    testPassed("Origin has isolated session.");
    106108                else
    107                     testPassed("Origin has no isolated session.");
     109                    testFailed("Origin has no isolated session.");
    108110                setEnableFeature(false, finishJSTest);
    109111                break;
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r283269 r283274  
     12021-09-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Use isolated NSURLSessions for each first party registrable domain
     4        https://bugs.webkit.org/show_bug.cgi?id=230750
     5        <rdar://83159358>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Rebaseline WPT test that is now passing more checks.
     10
     11        * web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt:
     12
    1132021-09-29  Aditya Keerthi  <akeerthi@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/connection-pool/network-partition-key-expected.txt

    r279344 r283274  
    11
    22
    3 FAIL With credentials promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    4 FAIL Without credentials promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    5 FAIL Cross-site resources with credentials promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    6 FAIL Cross-site resources without credentials promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    7 FAIL Iframes promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    8 FAIL Workers promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    9 FAIL Workers with cross-site resources promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
     3PASS With credentials
     4PASS Without credentials
     5PASS Cross-site resources with credentials
     6PASS Cross-site resources without credentials
     7PASS Iframes
     8PASS Workers
     9PASS Workers with cross-site resources
    1010FAIL CSP sandbox promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
    1111FAIL about:blank from opaque origin iframe promise_test: Unhandled rejection with value: "assert_equals: Socket unexpectedly reused expected \"ok\" but got \"Multiple partition IDs used on a socket\""
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r282847 r283274  
    896896
    897897webkit.org/b/209727 fast/forms/placeholder-content-line-height.html [ ImageOnlyFailure ]
    898 
    899 webkit.org/b/210487 http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction.py [ Failure ]
    900898
    901899webkit.org/b/210796 http/tests/resourceLoadStatistics/standalone-web-application-exempt-from-website-data-deletion.html [ Failure ]
  • trunk/LayoutTests/platform/wpe/TestExpectations

    r283094 r283274  
    598598webkit.org/b/210262 fast/selectors/text-field-selection-stroke-color.html [ ImageOnlyFailure ]
    599599webkit.org/b/210262 fast/selectors/text-field-selection-text-shadow.html [ ImageOnlyFailure ]
    600 
    601 webkit.org/b/210487 http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction.py [ Failure ]
    602600
    603601webkit.org/b/211563 fast/text-indicator/text-indicator-estimated-color-with-implicit-newline.html [ Failure ]
  • trunk/Source/WebCore/ChangeLog

    r283273 r283274  
     12021-09-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Use isolated NSURLSessions for each first party registrable domain
     4        https://bugs.webkit.org/show_bug.cgi?id=230750
     5        <rdar://83159358>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Fix bug where service worker soft-update requests would have their "first-party-for-cookies"
     10        field set to "https:" instead of a full origin (e.g. "https://localhost:8080"). This was
     11        causing some service worker test failures now that we use different NSURLSession based on
     12        the "first-party-for-cookies" field.
     13
     14        * workers/service/server/SWServer.cpp:
     15        (WebCore::originURL):
     16
    1172021-09-29  Devin Rousso  <drousso@apple.com>
    218
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r281854 r283274  
    441441URL static inline originURL(const SecurityOrigin& origin)
    442442{
    443     URL url;
    444     url.setProtocol(origin.protocol());
    445     url.setHost(origin.host());
    446     url.setPort(origin.port());
    447     return url;
     443    return URL(URL(), origin.data().toString());
    448444}
    449445
  • trunk/Source/WebKit/ChangeLog

    r283271 r283274  
     12021-09-29  Chris Dumez  <cdumez@apple.com>
     2
     3        Use isolated NSURLSessions for each first party registrable domain
     4        https://bugs.webkit.org/show_bug.cgi?id=230750
     5        <rdar://83159358>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Previously would use up to 10 isolated NSURLSessions only for domains marked as prevalent
     10        by ITP *and* that the user interacts with as first party website. We now use different
     11        isolated NSURLSession for each top-level registrable domain, not matter their ITP status.
     12        This significantly improves privacy.
     13
     14        To avoid having too many NSURLSession, we clear the ones that haven't been used in the
     15        last 10 minutes, every time we add a new one.
     16
     17        * NetworkProcess/cocoa/NetworkSessionCocoa.h:
     18        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     19        (WebKit::NetworkSessionCocoa::sessionWrapperForTask):
     20        (WebKit::SessionSet::isolatedSession):
     21
    1222021-09-29  Sihui Liu  <sihui_liu@apple.com>
    223
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h

    r279340 r283274  
    7070    SessionWrapper sessionWithCredentialStorage;
    7171    SessionWrapper sessionWithoutCredentialStorage;
    72     WallTime lastUsed;
     72    MonotonicTime lastUsed;
    7373};
    7474
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r282853 r283274  
    9797CFStringRef const WebKit2HTTPProxyDefaultsKey = static_cast<CFStringRef>(@"WebKit2HTTPProxy");
    9898CFStringRef const WebKit2HTTPSProxyDefaultsKey = static_cast<CFStringRef>(@"WebKit2HTTPSProxy");
    99 
    100 constexpr unsigned maxNumberOfIsolatedSessions { 10 };
    10199
    102100static NSURLSessionResponseDisposition toNSURLSessionResponseDisposition(WebCore::PolicyAction disposition)
     
    14411439    if (isParentProcessAFullWebBrowser(networkProcess()))
    14421440        shouldBeConsideredAppBound = NavigatingToAppBoundDomain::No;
    1443 #if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
    1444     if (auto* storageSession = networkStorageSession()) {
    1445         auto firstParty = WebCore::RegistrableDomain(request.firstPartyForCookies());
    1446         if (storageSession->shouldBlockThirdPartyCookiesButKeepFirstPartyCookiesFor(firstParty))
    1447             return sessionSetForPage(webPageProxyID).isolatedSession(storedCredentialsPolicy, firstParty, shouldBeConsideredAppBound, *this);
    1448     } else
    1449         ASSERT_NOT_REACHED();
    1450 #endif
    14511441
    14521442#if ENABLE(APP_BOUND_DOMAINS)
     
    14551445#endif
    14561446
    1457     switch (storedCredentialsPolicy) {
    1458     case WebCore::StoredCredentialsPolicy::Use:
    1459         return sessionSetForPage(webPageProxyID).sessionWithCredentialStorage;
    1460     case WebCore::StoredCredentialsPolicy::DoNotUse:
    1461         return sessionSetForPage(webPageProxyID).sessionWithoutCredentialStorage;
    1462     case WebCore::StoredCredentialsPolicy::EphemeralStateless:
    1463         return initializeEphemeralStatelessSessionIfNeeded(webPageProxyID, NavigatingToAppBoundDomain::No);
    1464     }
     1447    auto firstParty = WebCore::RegistrableDomain(request.firstPartyForCookies());
     1448    if (firstParty.isEmpty())
     1449        firstParty = WebCore::RegistrableDomain(request.url());
     1450
     1451    return sessionSetForPage(webPageProxyID).isolatedSession(storedCredentialsPolicy, firstParty, shouldBeConsideredAppBound, *this);
    14651452}
    14661453
     
    15191506SessionWrapper& SessionSet::isolatedSession(WebCore::StoredCredentialsPolicy storedCredentialsPolicy, const WebCore::RegistrableDomain firstPartyDomain, NavigatingToAppBoundDomain isNavigatingToAppBoundDomain, NetworkSessionCocoa& session)
    15201507{
    1521     auto& entry = isolatedSessions.ensure(firstPartyDomain, [this, &session, isNavigatingToAppBoundDomain] {
     1508    auto addResult = isolatedSessions.ensure(firstPartyDomain, [this, &session, isNavigatingToAppBoundDomain] {
    15221509        auto newEntry = makeUnique<IsolatedSession>();
    15231510        newEntry->sessionWithCredentialStorage.initialize(sessionWithCredentialStorage.session.get().configuration, session, WebCore::StoredCredentialsPolicy::Use, isNavigatingToAppBoundDomain);
    15241511        newEntry->sessionWithoutCredentialStorage.initialize(sessionWithoutCredentialStorage.session.get().configuration, session, WebCore::StoredCredentialsPolicy::DoNotUse, isNavigatingToAppBoundDomain);
    15251512        return newEntry;
    1526     }).iterator->value;
    1527 
    1528     entry->lastUsed = WallTime::now();
     1513    });
     1514
     1515    auto now = MonotonicTime::now();
     1516    auto& isolatedSession = addResult.iterator->value;
     1517    isolatedSession->lastUsed = now;
    15291518
    15301519    auto& sessionWrapper = [&] (auto storedCredentialsPolicy) -> SessionWrapper& {
     
    15321521        case WebCore::StoredCredentialsPolicy::Use:
    15331522            LOG(NetworkSession, "Using isolated NSURLSession with credential storage.");
    1534             return entry->sessionWithCredentialStorage;
     1523            return isolatedSession->sessionWithCredentialStorage;
    15351524        case WebCore::StoredCredentialsPolicy::DoNotUse:
    15361525            LOG(NetworkSession, "Using isolated NSURLSession without credential storage.");
    1537             return entry->sessionWithoutCredentialStorage;
     1526            return isolatedSession->sessionWithoutCredentialStorage;
    15381527        case WebCore::StoredCredentialsPolicy::EphemeralStateless:
    15391528            return initializeEphemeralStatelessSessionIfNeeded(isNavigatingToAppBoundDomain, session);
     
    15411530    } (storedCredentialsPolicy);
    15421531
    1543     if (isolatedSessions.size() > maxNumberOfIsolatedSessions) {
    1544         WebCore::RegistrableDomain keyToRemove;
    1545         auto oldestTimestamp = WallTime::now();
    1546         for (auto& key : isolatedSessions.keys()) {
    1547             auto timestamp = isolatedSessions.get(key)->lastUsed;
    1548             if (timestamp < oldestTimestamp) {
    1549                 oldestTimestamp = timestamp;
    1550                 keyToRemove = key;
    1551             }
    1552         }
    1553         LOG(NetworkSession, "About to remove isolated NSURLSession.");
    1554         isolatedSessions.remove(keyToRemove);
    1555     }
    1556 
    1557     RELEASE_ASSERT(isolatedSessions.size() <= maxNumberOfIsolatedSessions);
     1532    if (addResult.isNewEntry) {
     1533        isolatedSessions.removeIf([&](auto& entry) {
     1534            return (now - entry.value->lastUsed) > 10_min;
     1535        });
     1536    }
    15581537
    15591538    return sessionWrapper;
Note: See TracChangeset for help on using the changeset viewer.