diff --git a/docshell/base/WindowContext.cpp b/docshell/base/WindowContext.cpp index c773a561d442..a1299ec87045 100644 --- a/docshell/base/WindowContext.cpp +++ b/docshell/base/WindowContext.cpp @@ -228,6 +228,12 @@ bool WindowContext::CanSet(FieldIndex, return CheckOnlyOwningProcessCanSet(aSource); } +bool WindowContext::CanSet(FieldIndex, + const bool& aUsingStorageAccess, + ContentParent* aSource) { + return CheckOnlyOwningProcessCanSet(aSource); +} + bool WindowContext::CanSet(FieldIndex, const bool& aShouldResistFingerprinting, ContentParent* aSource) { diff --git a/docshell/base/WindowContext.h b/docshell/base/WindowContext.h index 9396ad9ed107..c38187679b7d 100644 --- a/docshell/base/WindowContext.h +++ b/docshell/base/WindowContext.h @@ -51,6 +51,9 @@ class BrowsingContextGroup; /* Whether this window's channel has been marked as a third-party \ * tracking resource */ \ FIELD(IsThirdPartyTrackingResourceWindow, bool) \ + /* Whether this window is using its unpartitioned cookies due to \ + * the Storage Access API */ \ + FIELD(UsingStorageAccess, bool) \ FIELD(ShouldResistFingerprinting, bool) \ FIELD(IsSecureContext, bool) \ FIELD(IsOriginalFrameSource, bool) \ @@ -266,6 +269,8 @@ class WindowContext : public nsISupports, public nsWrapperCache { bool CanSet(FieldIndex, const bool& aIsThirdPartyTrackingResourceWindow, ContentParent* aSource); + bool CanSet(FieldIndex, + const bool& aUsingStorageAccess, ContentParent* aSource); bool CanSet(FieldIndex, const bool& aShouldResistFingerprinting, ContentParent* aSource); bool CanSet(FieldIndex, const bool& aIsSecureContext, diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 30d07fec2209..f734a7fe03d6 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -18338,14 +18338,12 @@ nsICookieJarSettings* Document::CookieJarSettings() { } bool Document::UsingStorageAccess() { - // The HasStoragePermission flag in LoadInfo remains fixed when - // it is set in the parent process, so we need to check the cache - // to see if the permission is granted afterwards. - nsPIDOMWindowInner* inner = GetInnerWindow(); - if (inner && inner->UsingStorageAccess()) { - return true; + if (WindowContext* wc = GetWindowContext()) { + return wc->GetUsingStorageAccess(); } + // If we don't yet have a window context, we have to use the decision + // from the Document's Channel's LoadInfo directly. if (!mChannel) { return false; } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 53984ee4f0be..2d3ea5cf4fe4 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -7644,12 +7644,22 @@ const nsIGlobalObject* nsPIDOMWindowInner::AsGlobal() const { } void nsPIDOMWindowInner::SaveStorageAccessPermissionGranted() { - mUsingStorageAccess = true; + WindowContext* wc = GetWindowContext(); + if (wc) { + Unused << wc->SetUsingStorageAccess(true); + } nsGlobalWindowInner::Cast(this)->StorageAccessPermissionGranted(); } -bool nsPIDOMWindowInner::UsingStorageAccess() { return mUsingStorageAccess; } +bool nsPIDOMWindowInner::UsingStorageAccess() { + WindowContext* wc = GetWindowContext(); + if (!wc) { + return false; + } + + return wc->GetUsingStorageAccess(); +} nsPIDOMWindowInner::nsPIDOMWindowInner(nsPIDOMWindowOuter* aOuterWindow, WindowGlobalChild* aActor) @@ -7674,7 +7684,6 @@ nsPIDOMWindowInner::nsPIDOMWindowInner(nsPIDOMWindowOuter* aOuterWindow, mNumOfIndexedDBDatabases(0), mNumOfOpenWebSockets(0), mEvent(nullptr), - mUsingStorageAccess(false), mWindowGlobalChild(aActor), mWasSuspendedByGroup(false) { MOZ_ASSERT(aOuterWindow); diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 3a25a12869c6..06c36a9c88c6 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -760,10 +760,6 @@ class nsPIDOMWindowInner : public mozIDOMWindow { // the event object alive. mozilla::dom::Event* mEvent; - // A boolean flag indicating whether storage access is granted for the - // current window and that it is currently being used by this window. - bool mUsingStorageAccess; - // The WindowGlobalChild actor for this window. // // This will be non-null during the full lifetime of the window, initialized diff --git a/dom/ipc/WindowGlobalActor.cpp b/dom/ipc/WindowGlobalActor.cpp index ce5fa3eaf484..95d224a7b086 100644 --- a/dom/ipc/WindowGlobalActor.cpp +++ b/dom/ipc/WindowGlobalActor.cpp @@ -150,6 +150,8 @@ WindowGlobalInit WindowGlobalActor::WindowInitializer( nsCOMPtr loadInfo(channel->LoadInfo()); fields.Get() = loadInfo->GetOriginalFrameSrcLoad(); + fields.Get() = + loadInfo->GetStoragePermission() != nsILoadInfo::NoStoragePermission; channel->GetSecurityInfo(getter_AddRefs(securityInfo)); } diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 7270e664a47d..c8395895cf25 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -219,6 +219,8 @@ void WindowGlobalChild::OnNewDocument(Document* aDocument) { if (nsCOMPtr channel = aDocument->GetChannel()) { nsCOMPtr loadInfo(channel->LoadInfo()); txn.SetIsOriginalFrameSource(loadInfo->GetOriginalFrameSrcLoad()); + txn.SetUsingStorageAccess(loadInfo->GetStoragePermission() != + nsILoadInfo::NoStoragePermission); } else { txn.SetIsOriginalFrameSource(false); } diff --git a/toolkit/components/antitracking/AntiTrackingUtils.cpp b/toolkit/components/antitracking/AntiTrackingUtils.cpp index 59e2573d53fe..c80a6b869ca2 100644 --- a/toolkit/components/antitracking/AntiTrackingUtils.cpp +++ b/toolkit/components/antitracking/AntiTrackingUtils.cpp @@ -557,23 +557,23 @@ AntiTrackingUtils::GetStoragePermissionStateInParent(nsIChannel* aChannel) { return nsILoadInfo::HasStoragePermission; } } else if (!bc->IsTop()) { - // Only check the frame only permission if the channel is not in the top - // browsing context. - RefPtr etld = nsEffectiveTLDService::GetInstance(); - if (!etld) { + // For subframe resources, check if the document has storage access + // and that the resource being loaded is same-site to the page. + WindowContext* wc = bc->GetCurrentWindowContext(); + if (!wc) { return nsILoadInfo::NoStoragePermission; } - nsCString trackingSite; - rv = etld->GetSite(trackingURI, trackingSite); - if (NS_WARN_IF(NS_FAILED(rv))) { + WindowGlobalParent* wgp = wc->Canonical(); + if (!wgp) { return nsILoadInfo::NoStoragePermission; } - nsAutoCString type; - AntiTrackingUtils::CreateStorageFramePermissionKey(trackingSite, type); - - if (AntiTrackingUtils::CheckStoragePermission( - targetPrincipal, type, NS_UsePrivateBrowsing(aChannel), - &unusedReason, unusedReason)) { + nsIPrincipal* framePrincipal = wgp->DocumentPrincipal(); + if (!framePrincipal) { + return nsILoadInfo::NoStoragePermission; + } + bool isThirdParty = true; + nsresult rv = framePrincipal->IsThirdPartyURI(trackingURI, &isThirdParty); + if (NS_SUCCEEDED(rv) && wc->GetUsingStorageAccess() && !isThirdParty) { return nsILoadInfo::HasStoragePermission; } }