From fd4b32aa9ee3c822c44e7dc8728e9e87eb47a695 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Tue, 16 Jan 2024 09:22:16 +0000 Subject: [PATCH] Bug 1816390 - Partition the cache entries generated by cross-origin fetch requests r=necko-reviewers,kershaw,jesup Differential Revision: https://phabricator.services.mozilla.com/D195757 --- modules/libpref/init/StaticPrefList.yaml | 7 +++++++ netwerk/protocol/http/nsHttpChannel.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index c83537f17c8b..af2d6c7c384a 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -11429,6 +11429,13 @@ value: true mirror: always +# If true, cross origin fetch (or XHR) requests would be keyed +# with a different cache key. +- name: network.fetch.cache_partition_cross_origin + type: RelaxedAtomicBool + value: true + mirror: always + # Whether to strip auth headers for redirected http channels # https://fetch.spec.whatwg.org/#http-redirect-fetch - name: network.http.redirect.stripAuthHeader diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index b6ed87b72738..9480bcf9b088 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -3762,6 +3762,18 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) { if (mRequestHead.IsHead()) { mCacheIdExtension.Append("HEAD"); } + bool isThirdParty = false; + if (StaticPrefs::network_fetch_cache_partition_cross_origin() && + (NS_FAILED(mLoadInfo->TriggeringPrincipal()->IsThirdPartyChannel( + this, &isThirdParty)) || + isThirdParty) && + (mLoadInfo->InternalContentPolicyType() == nsIContentPolicy::TYPE_FETCH || + mLoadInfo->InternalContentPolicyType() == + nsIContentPolicy::TYPE_XMLHTTPREQUEST || + mLoadInfo->InternalContentPolicyType() == + nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST)) { + mCacheIdExtension.Append("FETCH"); + } mCacheOpenWithPriority = cacheEntryOpenFlags & nsICacheStorage::OPEN_PRIORITY; mCacheQueueSizeWhenOpen =