Skip to content

Commit 6212231

Browse files
jeffreyhxucharliewolfe
authored andcommitted
Add a flag to exempt certain cookies from ITP storage deletion.
rdar://190037411 Reviewed by Charlie Wolfe. Experimental flag, currently just for demo and investigation. No new tests. Tested by manually building and running. * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebKit/NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::setExemptAllowlistedCookiesFromITP): (WebKit::NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains): * Source/WebKit/NetworkProcess/NetworkProcess.h: * Source/WebKit/NetworkProcess/NetworkProcess.messages.in: * Source/WebKit/NetworkProcess/NetworkSession.cpp: (WebKit::m_dataStoreIdentifier): (WebKit::NetworkSession::setExemptAllowlistedCookiesFromITP): * Source/WebKit/NetworkProcess/NetworkSession.h: * Source/WebKit/NetworkProcess/cocoa/NetworkStorageSessionCocoa.mm: (WebKit::NetworkStorageSession::deleteCookiesForHostnames): (WebKit::isAllowlistedCookieName): * Source/WebKit/Shared/NetworkStorageSession.h: (WebKit::NetworkStorageSession::setExemptAllowlistedCookiesFromITP): (WebKit::NetworkStorageSession::exemptAllowlistedCookiesFromITP const): * Source/WebKit/Shared/ResourceLoadStatisticsParameters.h: * Source/WebKit/Shared/ResourceLoadStatisticsParameters.serialization.in: * Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp: (WebKit::NetworkProcessProxy::setExemptAllowlistedCookiesFromITP): * Source/WebKit/UIProcess/Network/NetworkProcessProxy.h: * Source/WebKit/UIProcess/WebPreferences.cpp: (WebKit::WebPreferences::updateBoolValueForKey): * Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: (WebKit::WebsiteDataStore::platformSetNetworkParameters): (WebKit::internalDebugFeatureEnabled): * Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp: (WebKit::WebsiteDataStore::setExemptAllowlistedCookiesFromITP): * Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h: * Source/WebKit/NetworkProcess/curl/NetworkStorageSessionCurl.cpp: (WebKit::NetworkStorageSession::deleteCookiesForHostnames): * Source/WebKit/NetworkProcess/soup/NetworkStorageSessionSoup.cpp: (WebKit::NetworkStorageSession::deleteCookiesForHostnames): * Source/WebKit/Shared/NetworkStorageSession.cpp: (WebKit::NetworkStorageSession::deleteCookiesForHostnames): Canonical link: https://commits.webkit.org/324047@main
1 parent ecfce4d commit 6212231

19 files changed

Lines changed: 81 additions & 8 deletions

‎Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,14 @@ EventTimingEnabled:
22222222
default: true
22232223
WebKitLegacy: false
22242224

2225+
ExemptAllowlistedCookiesFromItp:
2226+
type: bool
2227+
status: unstable
2228+
category: privacy
2229+
humanReadableName: "Exempt Allowlisted Cookies From ITP Data Removal"
2230+
humanReadableDescription: "Exempt allowlisted cookies and local storage from ITP data deletion"
2231+
defaultValue: false
2232+
22252233
ExperimentalSandboxEnabled:
22262234
type: bool
22272235
status: internal

‎Source/WebKit/NetworkProcess/NetworkProcess.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,13 @@ void NetworkProcess::setShouldEnbleSameSiteStrictEnforcementForTesting(PAL::Sess
16501650
completionHandler();
16511651
}
16521652

1653+
void NetworkProcess::setExemptAllowlistedCookiesFromITP(PAL::SessionID sessionID, bool exempt, CompletionHandler<void()>&& completionHandler)
1654+
{
1655+
if (CheckedPtr session = networkSession(sessionID))
1656+
session->setExemptAllowlistedCookiesFromITP(exempt);
1657+
completionHandler();
1658+
}
1659+
16531660
void NetworkProcess::setFirstPartyWebsiteDataRemovalModeForTesting(PAL::SessionID sessionID, WebCore::FirstPartyWebsiteDataRemovalMode mode, CompletionHandler<void()>&& completionHandler)
16541661
{
16551662
if (CheckedPtr session = networkSession(sessionID)) {
@@ -2327,19 +2334,19 @@ void NetworkProcess::deleteAndRestrictWebsiteDataForRegistrableDomains(PAL::Sess
23272334
networkStorageSession->getHostnamesWithCookies(hostNamesWithCookies);
23282335

23292336
const auto hostnamesWithCookiesToDelete = filterForRegistrableDomains(domains.domainsToDeleteAllCookiesFor, hostNamesWithCookies);
2330-
networkStorageSession->deleteCookiesForHostnames(hostnamesWithCookiesToDelete, WebCore::IncludeHttpOnlyCookies::Yes, ScriptWrittenCookiesOnly::No, [callbackAggregator] { });
2337+
networkStorageSession->deleteCookiesForHostnames(hostnamesWithCookiesToDelete, WebCore::IncludeHttpOnlyCookies::Yes, ScriptWrittenCookiesOnly::No, ExemptAllowlistedCookies::Yes, [callbackAggregator] { });
23312338

23322339
#if ENABLE(JS_COOKIE_CHECKING)
23332340
const auto hostnamesWithScriptWrittenCookiesToDelete = filterForRegistrableDomains(domains.domainsToDeleteAllScriptWrittenStorageFor, hostNamesWithCookies);
2334-
networkStorageSession->deleteCookiesForHostnames(hostnamesWithScriptWrittenCookiesToDelete, WebCore::IncludeHttpOnlyCookies::No, ScriptWrittenCookiesOnly::Yes, [callbackAggregator] { });
2341+
networkStorageSession->deleteCookiesForHostnames(hostnamesWithScriptWrittenCookiesToDelete, WebCore::IncludeHttpOnlyCookies::No, ScriptWrittenCookiesOnly::Yes, ExemptAllowlistedCookies::Yes, [callbackAggregator] { });
23352342
#else
23362343
const Vector<String> hostnamesWithScriptWrittenCookiesToDelete;
23372344
#endif
23382345
for (const auto& host : hostnamesWithCookiesToDelete)
23392346
callbackAggregator->m_domains.add(RegistrableDomain::uncheckedCreateFromHost(host));
23402347

23412348
const auto hostnamesWithCookiesToDeleteAllButHttpOnly = filterForRegistrableDomains(domains.domainsToDeleteAllButHttpOnlyCookiesFor, hostNamesWithCookies);
2342-
networkStorageSession->deleteCookiesForHostnames(hostnamesWithCookiesToDeleteAllButHttpOnly, WebCore::IncludeHttpOnlyCookies::No, ScriptWrittenCookiesOnly::No, [callbackAggregator] { });
2349+
networkStorageSession->deleteCookiesForHostnames(hostnamesWithCookiesToDeleteAllButHttpOnly, WebCore::IncludeHttpOnlyCookies::No, ScriptWrittenCookiesOnly::No, ExemptAllowlistedCookies::Yes, [callbackAggregator] { });
23432350

23442351
for (const auto& host : hostnamesWithCookiesToDeleteAllButHttpOnly)
23452352
callbackAggregator->m_domains.add(RegistrableDomain::uncheckedCreateFromHost(host));

‎Source/WebKit/NetworkProcess/NetworkProcess.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ class NetworkProcess final : public AuxiliaryProcess, private DownloadManager::C
326326
void setThirdPartyCookieBlockingMode(PAL::SessionID, WebCore::ThirdPartyCookieBlockingMode, CompletionHandler<void()>&&);
327327
void setShouldEnbleSameSiteStrictEnforcementForTesting(PAL::SessionID, WebCore::SameSiteStrictEnforcementEnabled, CompletionHandler<void()>&&);
328328
void setFirstPartyWebsiteDataRemovalModeForTesting(PAL::SessionID, WebCore::FirstPartyWebsiteDataRemovalMode, CompletionHandler<void()>&&);
329+
void setExemptAllowlistedCookiesFromITP(PAL::SessionID, bool, CompletionHandler<void()>&&);
329330
void setToSameSiteStrictCookiesForTesting(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void()>&&);
330331
void setFirstPartyHostCNAMEDomainForTesting(PAL::SessionID, String&& firstPartyHost, WebCore::RegistrableDomain&& cnameDomain, CompletionHandler<void()>&&);
331332
void setThirdPartyCNAMEDomainForTesting(PAL::SessionID, WebCore::RegistrableDomain&&, CompletionHandler<void()>&&);

‎Source/WebKit/NetworkProcess/NetworkProcess.messages.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ messages -> NetworkProcess : AuxiliaryProcess WantsAsyncDispatchMessage {
176176
SetThirdPartyCookieBlockingMode(PAL::SessionID sessionID, enum:uint8_t WebCore::ThirdPartyCookieBlockingMode blockingMode) -> ()
177177
SetShouldEnbleSameSiteStrictEnforcementForTesting(PAL::SessionID sessionID, enum:bool WebCore::SameSiteStrictEnforcementEnabled enabled) -> ()
178178
SetFirstPartyWebsiteDataRemovalModeForTesting(PAL::SessionID sessionID, enum:uint8_t WebCore::FirstPartyWebsiteDataRemovalMode mode) -> ()
179+
SetExemptAllowlistedCookiesFromITP(PAL::SessionID sessionID, bool exempt) -> ()
179180
SetToSameSiteStrictCookiesForTesting(PAL::SessionID sessionID, WebCore::RegistrableDomain domain) -> ()
180181
SetFirstPartyHostCNAMEDomainForTesting(PAL::SessionID sessionID, String firstPartyHost, WebCore::RegistrableDomain cnameDomain) -> ()
181182
SetThirdPartyCNAMEDomainForTesting(PAL::SessionID sessionID, WebCore::RegistrableDomain domain) -> ()

‎Source/WebKit/NetworkProcess/NetworkSession.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSess
307307
m_isStaleWhileRevalidateEnabled = parameters.staleWhileRevalidateEnabled;
308308

309309
setTrackingPreventionEnabled(parameters.resourceLoadStatisticsParameters.enabled);
310+
setExemptAllowlistedCookiesFromITP(parameters.resourceLoadStatisticsParameters.exemptAllowlistedCookiesFromITP);
310311

311312
setShouldSendPrivateTokenIPCForTesting(parameters.shouldSendPrivateTokenIPCForTesting);
312313
#if ENABLE(OPT_IN_PARTITIONED_COOKIES)
@@ -535,6 +536,12 @@ void NetworkSession::setShouldEnbleSameSiteStrictEnforcement(WebCore::SameSiteSt
535536
resourceLoadStatistics->setSameSiteStrictEnforcementEnabled(enabled);
536537
}
537538

539+
void NetworkSession::setExemptAllowlistedCookiesFromITP(bool exempt)
540+
{
541+
if (CheckedPtr storageSession = networkStorageSession())
542+
storageSession->setExemptAllowlistedCookiesFromITP(exempt);
543+
}
544+
538545
void NetworkSession::setFirstPartyHostCNAMEDomain(String&& firstPartyHost, WebCore::RegistrableDomain&& cnameDomain)
539546
{
540547
ASSERT(!firstPartyHost.isEmpty() && !cnameDomain.isEmpty() && firstPartyHost != cnameDomain.string());

‎Source/WebKit/NetworkProcess/NetworkSession.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class NetworkSession : public WebCore::SWServerDelegate, public CanMakeCheckedPt
163163
void setThirdPartyCookieBlockingMode(WebCore::ThirdPartyCookieBlockingMode);
164164
WebCore::ThirdPartyCookieBlockingMode thirdPartyCookieBlockingMode() const { return m_thirdPartyCookieBlockingMode; }
165165
void setShouldEnbleSameSiteStrictEnforcement(WebCore::SameSiteStrictEnforcementEnabled);
166+
void setExemptAllowlistedCookiesFromITP(bool);
166167
void setFirstPartyHostCNAMEDomain(String&& firstPartyHost, WebCore::RegistrableDomain&& cnameDomain);
167168
std::optional<WebCore::RegistrableDomain> firstPartyHostCNAMEDomain(const String& firstPartyHost);
168169
void setFirstPartyHostIPAddress(const String& firstPartyHost, const String& addressString);

‎Source/WebKit/NetworkProcess/cocoa/NetworkStorageSessionCocoa.mm‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
completionHandler(hasCookieForDomain);
122122
}
123123

124+
static bool isAllowlistedCookieName(const String& name)
125+
{
126+
// To be implemented.
127+
return false;
128+
}
129+
124130
void NetworkStorageSession::setAllCookiesToSameSiteStrict(const RegistrableDomain& domain, CompletionHandler<void()>&& completionHandler)
125131
{
126132
ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
@@ -342,7 +348,7 @@ static NSHTTPCookieAcceptPolicy httpCookieAcceptPolicy(CFHTTPCookieStorageRef co
342348
}, WTF::move(completionHandler));
343349
}
344350

345-
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> hostnames, IncludeHttpOnlyCookies includeHttpOnlyCookies, ScriptWrittenCookiesOnly scriptWrittenCookiesOnly, CompletionHandler<void()>&& completionHandler)
351+
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> hostnames, IncludeHttpOnlyCookies includeHttpOnlyCookies, ScriptWrittenCookiesOnly scriptWrittenCookiesOnly, ExemptAllowlistedCookies exemptAllowlistedCookies, CompletionHandler<void()>&& completionHandler)
346352
{
347353
HashSet<String> hostnamesSet;
348354
for (auto& hostname : hostnames)
@@ -351,6 +357,10 @@ static NSHTTPCookieAcceptPolicy httpCookieAcceptPolicy(CFHTTPCookieStorageRef co
351357
deleteCookiesMatching([&](NSHTTPCookie* cookie) {
352358
if (!cookie.domain || (includeHttpOnlyCookies == IncludeHttpOnlyCookies::No && cookie.isHTTPOnly))
353359
return false;
360+
if (exemptAllowlistedCookies == ExemptAllowlistedCookies::Yes && m_exemptAllowlistedCookiesFromITP) {
361+
if (isAllowlistedCookieName(cookie.name))
362+
return false;
363+
}
354364
#if ENABLE(JS_COOKIE_CHECKING)
355365
bool setInJS = [retainPtr([cookie properties]) valueForKey:@"SetInJavaScript"];
356366
if (scriptWrittenCookiesOnly == ScriptWrittenCookiesOnly::Yes && !setInJS)

‎Source/WebKit/NetworkProcess/curl/NetworkStorageSessionCurl.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime, CompletionHa
205205
completionHandler();
206206
}
207207

208-
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> cookieHostNames, IncludeHttpOnlyCookies includeHttpOnlyCookies, ScriptWrittenCookiesOnly, CompletionHandler<void()>&& completionHandler)
208+
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> cookieHostNames, IncludeHttpOnlyCookies includeHttpOnlyCookies, ScriptWrittenCookiesOnly, ExemptAllowlistedCookies, CompletionHandler<void()>&& completionHandler)
209209
{
210210
for (auto hostname : cookieHostNames)
211211
cookieDatabase().deleteCookiesForHostname(hostname, includeHttpOnlyCookies);

‎Source/WebKit/NetworkProcess/soup/NetworkStorageSessionSoup.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime timestamp, Co
599599
}
600600
}
601601

602-
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> hostnames, IncludeHttpOnlyCookies includeHttpOnlyCookies, ScriptWrittenCookiesOnly, CompletionHandler<void()>&& completionHandler)
602+
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> hostnames, IncludeHttpOnlyCookies includeHttpOnlyCookies, ScriptWrittenCookiesOnly, ExemptAllowlistedCookies, CompletionHandler<void()>&& completionHandler)
603603
{
604604
SoupCookieJar* cookieJar = cookieStorage();
605605
for (const auto& hostname : hostnames) {

‎Source/WebKit/Shared/NetworkStorageSession.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ std::optional<Seconds> NetworkStorageSession::clientSideCookieCap(const Registra
519519

520520
void NetworkStorageSession::deleteCookiesForHostnames(std::span<const String> cookieHostNames, CompletionHandler<void()>&& completionHandler)
521521
{
522-
deleteCookiesForHostnames(cookieHostNames, IncludeHttpOnlyCookies::Yes, ScriptWrittenCookiesOnly::No, WTF::move(completionHandler));
522+
deleteCookiesForHostnames(cookieHostNames, IncludeHttpOnlyCookies::Yes, ScriptWrittenCookiesOnly::No, ExemptAllowlistedCookies::No, WTF::move(completionHandler));
523523
}
524524

525525
#if !PLATFORM(COCOA)

0 commit comments

Comments
 (0)