Bug 1944310 - Make clearOrigin(nsIPrincipal) and clearOriginAttributes respect the partitionKey r=emz,necko-reviewers,edgul,valentin

Revert logic changes of Bug 1819147.

This makes the behavior of clearOriginAttributes again in sync with the
documentation:

> Evict any cache entry having the same originAttributes.[1]

`partitionKey` is part of the originAttributes[2], therefore both
functions shouldn't clear unrelated partitions.

To clear the cache (and other things) across partitionKeys,
a wildcard with `deleteByOriginAttributes()`[3] can be used.

To clear the cache for the "unpartitioned" for i.e. "http://example.com"
in `userContextId: 0`, it would then be necessary to pass the partition:

    Services.cache2.clearOriginAttributes(JSON.stringify({ userContextId:0, paritionKey: "(http,example.com)" }))

Outside of this patch it would be good to figured out why the need for
clearing across origins arose in Bug 1819147 to address that use case
separately.

[1]: https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/nsICacheStorageService.idl#71
[2]: https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/dom/chrome-webidl/ChromeUtils.webidl#960
[3]: https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/toolkit/components/cleardata/ClearDataService.sys.mjs#178-180

Differential Revision: https://phabricator.services.mozilla.com/D238074
This commit is contained in:
Manuel Bucher
2025-02-21 17:08:27 +00:00
parent b9d2a66ca2
commit 5c579edfc3
5 changed files with 34 additions and 12 deletions

View File

@@ -64,12 +64,6 @@ interface nsILoadContextInfo : nsISupports
return IsAnonymous() == aOther->IsAnonymous() &&
*OriginAttributesPtr() == *aOther->OriginAttributesPtr();
}
bool EqualsIgnoringFPD(nsILoadContextInfo *aOther)
{
return IsAnonymous() == aOther->IsAnonymous() &&
OriginAttributesPtr()->EqualsIgnoringFPD(*aOther->OriginAttributesPtr());
}
%}
};

View File

@@ -3314,7 +3314,7 @@ nsresult CacheFileIOManager::EvictByContextInternal(
}
// Filter by LoadContextInfo.
if (aLoadContextInfo && !info->EqualsIgnoringFPD(aLoadContextInfo)) {
if (aLoadContextInfo && !info->Equals(aLoadContextInfo)) {
return false;
}

View File

@@ -75,7 +75,7 @@ add_task(
await test(
{ userContextId: 0, partitionKey: "(https,example.com)" },
{ userContextId: 0 },
false
true
);
}
);

View File

@@ -1,8 +1,7 @@
prefs: [privacy.clearSiteDataHeader.cache.enabled:true]
[clear-cache-partitioning.sub.https.html]
[clear in cross origin iframe doesn't clear unpartitioned data from that cross origin]
expected: FAIL
[clear in unpartitioned context doesn't clear partitioned data]
expected:
if tsan: TIMEOUT
[same site data also gets cleared in iframe]
expected: FAIL

View File

@@ -1,2 +1,31 @@
[clear-cache.https.html]
prefs: [privacy.clearSiteDataHeader.cache.enabled:true]
[clear cache: Document with clear-cache header doesn't get cached]
expected: FAIL
[clear all: Document with clear-cache header doesn't get cached]
expected: FAIL
[clear cache: Fetch on docment with clear-cache header doesn't get cached]
expected: FAIL
[clear all: Fetch on docment with clear-cache header doesn't get cached]
expected: FAIL
[clear cache: Previously cached fetch gets cleared]
expected: FAIL
[clear all: Previously cached fetch gets cleared]
expected: FAIL
[clear cache: Clear fetch on intermediate navigation]
expected: FAIL
[clear all: Clear fetch on intermediate navigation]
expected: FAIL
[clear cache: Clear document in intermediate load]
expected: FAIL
[clear all: Clear document in intermediate load]
expected: FAIL