From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- netwerk/cookie/Cookie.cpp | 8 ++++---- netwerk/cookie/CookieJarSettings.cpp | 27 +++++++++++++++++++++++---- netwerk/cookie/CookieJarSettings.h | 13 ++++++++++++- netwerk/cookie/CookiePersistentStorage.cpp | 20 ++++++++++---------- netwerk/cookie/CookieStorage.cpp | 8 ++++---- 5 files changed, 53 insertions(+), 23 deletions(-) (limited to 'netwerk/cookie') diff --git a/netwerk/cookie/Cookie.cpp b/netwerk/cookie/Cookie.cpp index e9de561f88..e78c11e50d 100644 --- a/netwerk/cookie/Cookie.cpp +++ b/netwerk/cookie/Cookie.cpp @@ -100,8 +100,8 @@ already_AddRefed Cookie::CreateValidated( if (cookie->mData.creationTime() > currentTimeInUsec) { uint64_t diffInSeconds = (cookie->mData.creationTime() - currentTimeInUsec) / PR_USEC_PER_SEC; - mozilla::glean::networking::cookie_creation_fixup_diff.AccumulateSamples( - {diffInSeconds}); + mozilla::glean::networking::cookie_creation_fixup_diff + .AccumulateSingleSample(diffInSeconds); glean::networking::cookie_timestamp_fixed_count.Get("creationTime"_ns) .Add(1); @@ -112,8 +112,8 @@ already_AddRefed Cookie::CreateValidated( if (cookie->mData.lastAccessed() > currentTimeInUsec) { uint64_t diffInSeconds = (cookie->mData.lastAccessed() - currentTimeInUsec) / PR_USEC_PER_SEC; - mozilla::glean::networking::cookie_access_fixup_diff.AccumulateSamples( - {diffInSeconds}); + mozilla::glean::networking::cookie_access_fixup_diff.AccumulateSingleSample( + diffInSeconds); glean::networking::cookie_timestamp_fixed_count.Get("lastAccessed"_ns) .Add(1); diff --git a/netwerk/cookie/CookieJarSettings.cpp b/netwerk/cookie/CookieJarSettings.cpp index 09a4789d85..9e598c296f 100644 --- a/netwerk/cookie/CookieJarSettings.cpp +++ b/netwerk/cookie/CookieJarSettings.cpp @@ -4,9 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozIThirdPartyUtil.h" #include "mozilla/AntiTrackingUtils.h" #include "mozilla/BasePrincipal.h" #include "mozilla/ClearOnShutdown.h" +#include "mozilla/Components.h" #include "mozilla/ContentBlockingAllowList.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/net/CookieJarSettings.h" @@ -15,6 +17,7 @@ #include "mozilla/PermissionManager.h" #include "mozilla/SchedulerGroup.h" #include "mozilla/StaticPrefs_network.h" +#include "mozilla/StoragePrincipalHelper.h" #include "mozilla/Unused.h" #include "nsIPrincipal.h" #if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE) @@ -172,7 +175,8 @@ CookieJarSettings::CookieJarSettings(uint32_t aCookieBehavior, mIsOnContentBlockingAllowListUpdated(false), mState(aState), mToBeMerged(false), - mShouldResistFingerprinting(aShouldResistFingerprinting) { + mShouldResistFingerprinting(aShouldResistFingerprinting), + mTopLevelWindowContextId(0) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT_IF( mIsFirstPartyIsolated, @@ -195,7 +199,7 @@ CookieJarSettings::InitWithURI(nsIURI* aURI, bool aIsPrivate) { mCookieBehavior = nsICookieManager::GetCookieBehavior(aIsPrivate); - SetPartitionKey(aURI); + SetPartitionKey(aURI, false); return NS_OK; } @@ -408,6 +412,8 @@ void CookieJarSettings::Serialize(CookieJarSettingsArgs& aData) { CookiePermissionData(principalInfo, cookiePermission)); } + aData.topLevelWindowContextId() = mTopLevelWindowContextId; + mToBeMerged = false; } @@ -451,6 +457,8 @@ void CookieJarSettings::Serialize(CookieJarSettingsArgs& aData) { aData.fingerprintingRandomizationKey().Clone()); } + cookieJarSettings->mTopLevelWindowContextId = aData.topLevelWindowContextId(); + cookieJarSettings.forget(aCookieJarSettings); } @@ -521,14 +529,25 @@ void CookieJarSettings::Merge(const CookieJarSettingsArgs& aData) { } } -void CookieJarSettings::SetPartitionKey(nsIURI* aURI) { +void CookieJarSettings::SetPartitionKey(nsIURI* aURI, + bool aForeignByAncestorContext) { MOZ_ASSERT(aURI); OriginAttributes attrs; - attrs.SetPartitionKey(aURI); + attrs.SetPartitionKey(aURI, aForeignByAncestorContext); mPartitionKey = std::move(attrs.mPartitionKey); } +void CookieJarSettings::UpdatePartitionKeyForDocumentLoadedByChannel( + nsIChannel* aChannel) { + nsCOMPtr loadInfo = aChannel->LoadInfo(); + bool thirdParty = AntiTrackingUtils::IsThirdPartyChannel(aChannel); + bool foreignByAncestorContext = + thirdParty && !loadInfo->GetIsThirdPartyContextToTopWindow(); + StoragePrincipalHelper::UpdatePartitionKeyWithForeignAncestorBit( + mPartitionKey, foreignByAncestorContext); +} + void CookieJarSettings::UpdateIsOnContentBlockingAllowList( nsIChannel* aChannel) { MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess()); diff --git a/netwerk/cookie/CookieJarSettings.h b/netwerk/cookie/CookieJarSettings.h index 97f8528a55..cf3c9ff418 100644 --- a/netwerk/cookie/CookieJarSettings.h +++ b/netwerk/cookie/CookieJarSettings.h @@ -161,12 +161,14 @@ class CookieJarSettings final : public nsICookieJarSettings { void UpdateIsOnContentBlockingAllowList(nsIChannel* aChannel); - void SetPartitionKey(nsIURI* aURI); + void SetPartitionKey(nsIURI* aURI, bool aForeignByAncestorContext); void SetPartitionKey(const nsAString& aPartitionKey) { mPartitionKey = aPartitionKey; } const nsAString& GetPartitionKey() { return mPartitionKey; }; + void UpdatePartitionKeyForDocumentLoadedByChannel(nsIChannel* aChannel); + void SetFingerprintingRandomizationKey(const nsTArray& aKey) { mFingerprintingRandomKey.reset(); @@ -179,6 +181,11 @@ class CookieJarSettings final : public nsICookieJarSettings { // network.cookie.rejectForeignWithExceptions.enabled pref is set to true. static bool IsRejectThirdPartyContexts(uint32_t aCookieBehavior); + void SetTopLevelWindowContextId(uint64_t aId) { + mTopLevelWindowContextId = aId; + } + uint64_t GetTopLevelWindowContextId() { return mTopLevelWindowContextId; } + private: enum State { // No cookie permissions are allowed to be stored in this object. @@ -259,6 +266,10 @@ class CookieJarSettings final : public nsICookieJarSettings { // browsing session changes. This can prevent trackers to identify individuals // by using browser fingerprints. Maybe> mFingerprintingRandomKey; + + // This field caches the top level window context id when loading the top + // level document. + uint64_t mTopLevelWindowContextId; }; } // namespace net diff --git a/netwerk/cookie/CookiePersistentStorage.cpp b/netwerk/cookie/CookiePersistentStorage.cpp index 6358b39e3a..57727ad4fc 100644 --- a/netwerk/cookie/CookiePersistentStorage.cpp +++ b/netwerk/cookie/CookiePersistentStorage.cpp @@ -2105,22 +2105,22 @@ void CookiePersistentStorage::CollectCookieJarSizeData() { if (cookieEntry.IsPartitioned()) { uint16_t cePartitioned = cookieEntry.GetCookies().Length(); sumPartitioned += cePartitioned; - mozilla::glean::networking::cookie_count_part_by_key.AccumulateSamples( - {cePartitioned}); + mozilla::glean::networking::cookie_count_part_by_key + .AccumulateSingleSample(cePartitioned); } else { uint16_t ceUnpartitioned = cookieEntry.GetCookies().Length(); sumUnpartitioned += ceUnpartitioned; - mozilla::glean::networking::cookie_count_unpart_by_key.AccumulateSamples( - {ceUnpartitioned}); + mozilla::glean::networking::cookie_count_unpart_by_key + .AccumulateSingleSample(ceUnpartitioned); } } - mozilla::glean::networking::cookie_count_total.AccumulateSamples( - {mCookieCount}); - mozilla::glean::networking::cookie_count_partitioned.AccumulateSamples( - {sumPartitioned}); - mozilla::glean::networking::cookie_count_unpartitioned.AccumulateSamples( - {sumUnpartitioned}); + mozilla::glean::networking::cookie_count_total.AccumulateSingleSample( + mCookieCount); + mozilla::glean::networking::cookie_count_partitioned.AccumulateSingleSample( + sumPartitioned); + mozilla::glean::networking::cookie_count_unpartitioned.AccumulateSingleSample( + sumUnpartitioned); } } // namespace net diff --git a/netwerk/cookie/CookieStorage.cpp b/netwerk/cookie/CookieStorage.cpp index fd0af6129b..ef4af82b64 100644 --- a/netwerk/cookie/CookieStorage.cpp +++ b/netwerk/cookie/CookieStorage.cpp @@ -669,8 +669,8 @@ void CookieStorage::AddCookie(nsIConsoleReportCollector* aCRC, } uint32_t purgedLength = 0; purgedList->GetLength(&purgedLength); - mozilla::glean::networking::cookie_purge_entry_max.AccumulateSamples( - {purgedLength}); + mozilla::glean::networking::cookie_purge_entry_max.AccumulateSingleSample( + purgedLength); } else if (mCookieCount >= ADD_TEN_PERCENT(mMaxNumberOfCookies)) { int64_t maxAge = aCurrentTimeInUsec - mCookieOldestTime; @@ -687,8 +687,8 @@ void CookieStorage::AddCookie(nsIConsoleReportCollector* aCRC, mCookiePurgeAge); uint32_t purgedLength = 0; purgedList->GetLength(&purgedLength); - mozilla::glean::networking::cookie_purge_max.AccumulateSamples( - {purgedLength}); + mozilla::glean::networking::cookie_purge_max.AccumulateSingleSample( + purgedLength); } } } -- cgit v1.2.3