Skip to content

Commit

Permalink
Backed out 3 changesets (bug 1758745, bug 1758740, bug 1762462) for c…
Browse files Browse the repository at this point in the history
…ausing failures at browser_storage_dfpi.js. CLOSED TREE

Backed out changeset a3024e8b2a58 (bug 1762462)
Backed out changeset 8bc1291b9bdb (bug 1758745)
Backed out changeset c7b693b2fd05 (bug 1758740)
  • Loading branch information
Butkovits Atila committed May 10, 2022
1 parent 0db58fc commit 581d548
Show file tree
Hide file tree
Showing 30 changed files with 136 additions and 505 deletions.
34 changes: 8 additions & 26 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6479,7 +6479,7 @@ void Document::GetCookie(nsAString& aCookie, ErrorResult& rv) {
return;
}

StorageAccess storageAccess = CookieAllowedForDocument(this);
StorageAccess storageAccess = StorageAllowedForDocument(this);
if (storageAccess == StorageAccess::eDeny) {
return;
}
Expand Down Expand Up @@ -6518,7 +6518,7 @@ void Document::SetCookie(const nsAString& aCookie, ErrorResult& aRv) {
return;
}

StorageAccess storageAccess = CookieAllowedForDocument(this);
StorageAccess storageAccess = StorageAllowedForDocument(this);
if (storageAccess == StorageAccess::eDeny) {
return;
}
Expand Down Expand Up @@ -12051,7 +12051,7 @@ nsresult Document::CloneDocHelper(Document* clone) const {
clone->SetDocumentURI(Document::GetDocumentURI());
clone->SetChromeXHRDocURI(mChromeXHRDocURI);
clone->SetPrincipals(NodePrincipal(), mPartitionedPrincipal);
clone->mActiveCookiePrincipal = mActiveCookiePrincipal;
clone->mActiveStoragePrincipal = mActiveStoragePrincipal;
// NOTE(emilio): Intentionally setting this to the GetDocBaseURI rather than
// just mDocumentBaseURI, so that srcdoc iframes get the right base URI even
// when printed standalone via window.print() (where there won't be a parent
Expand Down Expand Up @@ -17714,40 +17714,22 @@ bool Document::HasStorageAccessPermissionGrantedByAllowList() {
}

nsIPrincipal* Document::EffectiveStoragePrincipal() const {
if (!StaticPrefs::privacy_partition_always_partition_non_cookie_storage()) {
return EffectiveCookiePrincipal();
}

nsPIDOMWindowInner* inner = GetInnerWindow();
if (!inner || inner->GetExtantDoc() != this) {
return NodePrincipal();
}

nsCOMPtr<nsIPrincipal> foreignPartitionedPrincipal;
Unused << NS_WARN_IF(NS_FAILED(StoragePrincipalHelper::GetPrincipal(
nsGlobalWindowInner::Cast(inner),
StoragePrincipalHelper::eForeignPartitionedPrincipal,
getter_AddRefs(foreignPartitionedPrincipal))));
return foreignPartitionedPrincipal;
}

nsIPrincipal* Document::EffectiveCookiePrincipal() const {
nsPIDOMWindowInner* inner = GetInnerWindow();
if (!inner) {
return NodePrincipal();
}

// Return our cached storage principal if one exists.
if (mActiveCookiePrincipal) {
return mActiveCookiePrincipal;
if (mActiveStoragePrincipal) {
return mActiveStoragePrincipal;
}

// We use the lower-level ContentBlocking API here to ensure this
// check doesn't send notifications.
uint32_t rejectedReason = 0;
if (ContentBlocking::ShouldAllowAccessFor(inner, GetDocumentURI(),
&rejectedReason)) {
return mActiveCookiePrincipal = NodePrincipal();
return mActiveStoragePrincipal = NodePrincipal();
}

// Let's use the storage principal only if we need to partition the cookie
Expand All @@ -17756,10 +17738,10 @@ nsIPrincipal* Document::EffectiveCookiePrincipal() const {
if (ShouldPartitionStorage(rejectedReason) &&
!StoragePartitioningEnabled(
rejectedReason, const_cast<Document*>(this)->CookieJarSettings())) {
return mActiveCookiePrincipal = NodePrincipal();
return mActiveStoragePrincipal = NodePrincipal();
}

return mActiveCookiePrincipal = mPartitionedPrincipal;
return mActiveStoragePrincipal = mPartitionedPrincipal;
}

nsIPrincipal* Document::GetPrincipalForPrefBasedHacks() const {
Expand Down
14 changes: 4 additions & 10 deletions dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,17 +640,11 @@ class Document : public nsINode,
return DocumentOrShadowRoot::SetValueMissingState(aName, aValue);
}

nsIPrincipal* EffectiveCookiePrincipal() const;

nsIPrincipal* EffectiveStoragePrincipal() const;

// nsIScriptObjectPrincipal
nsIPrincipal* GetPrincipal() final { return NodePrincipal(); }

nsIPrincipal* GetEffectiveCookiePrincipal() final {
return EffectiveCookiePrincipal();
}

nsIPrincipal* GetEffectiveStoragePrincipal() final {
return EffectiveStoragePrincipal();
}
Expand All @@ -665,7 +659,7 @@ class Document : public nsINode,
// allowlist.
nsIPrincipal* GetPrincipalForPrefBasedHacks() const;

void ClearActiveCookiePrincipal() { mActiveCookiePrincipal = nullptr; }
void ClearActiveStoragePrincipal() { mActiveStoragePrincipal = nullptr; }

// EventTarget
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
Expand Down Expand Up @@ -5280,10 +5274,10 @@ class Document : public nsINode,
// StoragePrincipalHelper.h to know more.
nsCOMPtr<nsIPrincipal> mPartitionedPrincipal;

// The cached cookie principal for this document.
// This is mutable so that we can keep EffectiveCookiePrincipal() const
// The cached storage principal for this document.
// This is mutable so that we can keep EffectiveStoragePrincipal() const
// which is required due to its CloneDocHelper() call site. :-(
mutable nsCOMPtr<nsIPrincipal> mActiveCookiePrincipal;
mutable nsCOMPtr<nsIPrincipal> mActiveStoragePrincipal;

// See GetNextFormNumber and GetNextControlNumber.
int32_t mNextFormNumber;
Expand Down
46 changes: 11 additions & 35 deletions dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,6 @@ class nsGlobalWindowObserver final : public nsIObserver,
}
}

nsIPrincipal* GetEffectiveCookiePrincipal() const override {
return mWindow ? mWindow->GetEffectiveCookiePrincipal() : nullptr;
}

nsIPrincipal* GetEffectiveStoragePrincipal() const override {
return mWindow ? mWindow->GetEffectiveStoragePrincipal() : nullptr;
}
Expand Down Expand Up @@ -1181,7 +1177,7 @@ void nsGlobalWindowInner::FreeInnerObjects() {
if (mDoc) {
// Remember the document's principal, URI, and CSP.
mDocumentPrincipal = mDoc->NodePrincipal();
mDocumentCookiePrincipal = mDoc->EffectiveCookiePrincipal();
mDocumentStoragePrincipal = mDoc->EffectiveStoragePrincipal();
mDocumentPartitionedPrincipal = mDoc->PartitionedPrincipal();
mDocumentURI = mDoc->GetDocumentURI();
mDocBaseURI = mDoc->GetDocBaseURI();
Expand Down Expand Up @@ -1426,8 +1422,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mApplicationCache)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentCookiePrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentForeignPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentCsp)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserChild)
Expand Down Expand Up @@ -1545,8 +1540,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB)
}
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentCookiePrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentForeignPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentCsp)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBrowserChild)
Expand Down Expand Up @@ -2273,14 +2267,14 @@ nsIPrincipal* nsGlobalWindowInner::GetPrincipal() {
return nullptr;
}

nsIPrincipal* nsGlobalWindowInner::GetEffectiveCookiePrincipal() {
nsIPrincipal* nsGlobalWindowInner::GetEffectiveStoragePrincipal() {
if (mDoc) {
// If we have a document, get the principal from the document
return mDoc->EffectiveCookiePrincipal();
return mDoc->EffectiveStoragePrincipal();
}

if (mDocumentCookiePrincipal) {
return mDocumentCookiePrincipal;
if (mDocumentStoragePrincipal) {
return mDocumentStoragePrincipal;
}

// If we don't have a storage principal and we don't have a document we ask
Expand All @@ -2290,30 +2284,12 @@ nsIPrincipal* nsGlobalWindowInner::GetEffectiveCookiePrincipal() {
do_QueryInterface(GetInProcessParentInternal());

if (objPrincipal) {
return objPrincipal->GetEffectiveCookiePrincipal();
return objPrincipal->GetEffectiveStoragePrincipal();
}

return nullptr;
}

nsIPrincipal* nsGlobalWindowInner::GetEffectiveStoragePrincipal() {
if (StaticPrefs::privacy_partition_always_partition_non_cookie_storage()) {
return ForeignPartitionedPrincipal();
}

return GetEffectiveCookiePrincipal();
}

nsIPrincipal* nsGlobalWindowInner::ForeignPartitionedPrincipal() {
if (!mDocumentForeignPartitionedPrincipal) {
Unused << NS_WARN_IF(NS_FAILED(StoragePrincipalHelper::GetPrincipal(
this, StoragePrincipalHelper::eForeignPartitionedPrincipal,
getter_AddRefs(mDocumentForeignPartitionedPrincipal))));
}

return mDocumentForeignPartitionedPrincipal;
}

nsIPrincipal* nsGlobalWindowInner::PartitionedPrincipal() {
if (mDoc) {
// If we have a document, get the principal from the document
Expand Down Expand Up @@ -7778,11 +7754,11 @@ void nsGlobalWindowInner::StorageAccessPermissionGranted() {
// Reset DOM Cache
mCacheStorage = nullptr;

// Reset the active cookie principal
// Reset the active storage principal
if (mDoc) {
mDoc->ClearActiveCookiePrincipal();
mDoc->ClearActiveStoragePrincipal();
if (mWindowGlobalChild) {
// XXX(farre): This is a bit backwards, but clearing the cookie
// XXX(farre): This is a bit backwards, but clearing the storage
// principal might make us end up with a new effective storage
// principal on the child side than on the parent side, which
// means that we need to sync it. See bug 1705359.
Expand Down
7 changes: 1 addition & 6 deletions dom/base/nsGlobalWindowInner.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,8 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal() override;

virtual nsIPrincipal* GetEffectiveCookiePrincipal() override;

virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;

nsIPrincipal* ForeignPartitionedPrincipal();

virtual nsIPrincipal* PartitionedPrincipal() override;

// nsIDOMWindow
Expand Down Expand Up @@ -1467,8 +1463,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
// The document's principals and CSP are only stored if
// FreeInnerObjects has been called.
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsCOMPtr<nsIPrincipal> mDocumentCookiePrincipal;
nsCOMPtr<nsIPrincipal> mDocumentForeignPartitionedPrincipal;
nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;
nsCOMPtr<nsIContentSecurityPolicy> mDocumentCsp;

Expand Down
45 changes: 10 additions & 35 deletions dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "mozilla/dom/WindowFeatures.h" // WindowFeatures
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/StoragePrincipalHelper.h"
#include "nsBaseCommandController.h"
#include "nsError.h"
#include "nsICookieService.h"
Expand Down Expand Up @@ -1576,8 +1575,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowOuter)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocalStorage)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedDocs)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentCookiePrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentForeignPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)

Expand Down Expand Up @@ -1609,8 +1607,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowOuter)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocalStorage)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedDocs)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentCookiePrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentForeignPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc)

Expand Down Expand Up @@ -2071,12 +2068,11 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
WindowGlobalChild* aActor) {
MOZ_ASSERT(mDocumentPrincipal == nullptr,
"mDocumentPrincipal prematurely set!");
MOZ_ASSERT(mDocumentCookiePrincipal == nullptr,
"mDocumentCookiePrincipal prematurely set!");
MOZ_ASSERT(mDocumentStoragePrincipal == nullptr,
"mDocumentStoragePrincipal prematurely set!");
MOZ_ASSERT(mDocumentPartitionedPrincipal == nullptr,
"mDocumentPartitionedPrincipal prematurely set!");
MOZ_ASSERT(aDocument);
mDocumentForeignPartitionedPrincipal = nullptr;

// Bail out early if we're in process of closing down the window.
NS_ENSURE_STATE(!mCleanedUp);
Expand Down Expand Up @@ -2711,7 +2707,7 @@ void nsGlobalWindowOuter::DetachFromDocShell(bool aIsBeingDiscarded) {

// Remember the document's principal and URI.
mDocumentPrincipal = mDoc->NodePrincipal();
mDocumentCookiePrincipal = mDoc->EffectiveCookiePrincipal();
mDocumentStoragePrincipal = mDoc->EffectiveStoragePrincipal();
mDocumentPartitionedPrincipal = mDoc->PartitionedPrincipal();
mDocumentURI = mDoc->GetDocumentURI();

Expand Down Expand Up @@ -2945,14 +2941,14 @@ nsIPrincipal* nsGlobalWindowOuter::GetPrincipal() {
return nullptr;
}

nsIPrincipal* nsGlobalWindowOuter::GetEffectiveCookiePrincipal() {
nsIPrincipal* nsGlobalWindowOuter::GetEffectiveStoragePrincipal() {
if (mDoc) {
// If we have a document, get the principal from the document
return mDoc->EffectiveCookiePrincipal();
return mDoc->EffectiveStoragePrincipal();
}

if (mDocumentCookiePrincipal) {
return mDocumentCookiePrincipal;
if (mDocumentStoragePrincipal) {
return mDocumentStoragePrincipal;
}

// If we don't have a storage principal and we don't have a document we ask
Expand All @@ -2962,33 +2958,12 @@ nsIPrincipal* nsGlobalWindowOuter::GetEffectiveCookiePrincipal() {
do_QueryInterface(GetInProcessParentInternal());

if (objPrincipal) {
return objPrincipal->GetEffectiveCookiePrincipal();
return objPrincipal->GetEffectiveStoragePrincipal();
}

return nullptr;
}

nsIPrincipal* nsGlobalWindowOuter::GetEffectiveStoragePrincipal() {
if (StaticPrefs::privacy_partition_always_partition_non_cookie_storage()) {
return ForeignPartitionedPrincipal();
}

return GetEffectiveCookiePrincipal();
}

nsIPrincipal* nsGlobalWindowOuter::ForeignPartitionedPrincipal() {
if (!mDocumentForeignPartitionedPrincipal) {
RefPtr<nsGlobalWindowInner> inner = GetCurrentInnerWindowInternal();
if (!NS_WARN_IF(!inner)) {
Unused << NS_WARN_IF(NS_FAILED(StoragePrincipalHelper::GetPrincipal(
inner, StoragePrincipalHelper::eForeignPartitionedPrincipal,
getter_AddRefs(mDocumentForeignPartitionedPrincipal))));
}
}

return mDocumentForeignPartitionedPrincipal;
}

nsIPrincipal* nsGlobalWindowOuter::PartitionedPrincipal() {
if (mDoc) {
// If we have a document, get the principal from the document
Expand Down
7 changes: 1 addition & 6 deletions dom/base/nsGlobalWindowOuter.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,8 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal() override;

virtual nsIPrincipal* GetEffectiveCookiePrincipal() override;

virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;

nsIPrincipal* ForeignPartitionedPrincipal();

virtual nsIPrincipal* PartitionedPrincipal() override;

// nsIDOMWindow
Expand Down Expand Up @@ -1117,8 +1113,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
RefPtr<mozilla::dom::Storage> mLocalStorage;

nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsCOMPtr<nsIPrincipal> mDocumentCookiePrincipal;
nsCOMPtr<nsIPrincipal> mDocumentForeignPartitionedPrincipal;
nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;

#ifdef DEBUG
Expand Down
2 changes: 0 additions & 2 deletions dom/base/nsIScriptObjectPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class nsIScriptObjectPrincipal : public nsISupports {

virtual nsIPrincipal* GetPrincipal() = 0;

virtual nsIPrincipal* GetEffectiveCookiePrincipal() = 0;

virtual nsIPrincipal* GetEffectiveStoragePrincipal() = 0;

virtual nsIPrincipal* PartitionedPrincipal() = 0;
Expand Down
Loading

0 comments on commit 581d548

Please sign in to comment.