Skip to content

Commit

Permalink
Backed out 5 changesets (bug 1765313, bug 1770403) for causing bc fai…
Browse files Browse the repository at this point in the history
…lures on browser_storageAccessPrivilegeAPI.js. CLOSED TREE

Backed out changeset 22153c8641e1 (bug 1765313)
Backed out changeset 588d54f796a0 (bug 1765313)
Backed out changeset 2376ca53eb9c (bug 1765313)
Backed out changeset 9cf02ec5657a (bug 1770403)
Backed out changeset 7d8147ba25e8 (bug 1770403)
  • Loading branch information
Marian-Vasile Laza committed Jun 8, 2022
1 parent 0a3aa8e commit a0f6973
Show file tree
Hide file tree
Showing 34 changed files with 916 additions and 801 deletions.
5 changes: 3 additions & 2 deletions caps/BasePrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "prnetdb.h"
#include "nsIURIFixup.h"
#include "mozilla/dom/StorageUtils.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/ContentBlocking.h"
#include "nsPIDOMWindow.h"
#include "nsIURIMutator.h"
#include "mozilla/PermissionManager.h"
Expand Down Expand Up @@ -785,7 +785,8 @@ BasePrincipal::HasFirstpartyStorageAccess(mozIDOMWindow* aCheckWindow,
if (NS_FAILED(rv)) {
return rv;
}
*aOutAllowed = ShouldAllowAccessFor(win, uri, aRejectedReason);
*aOutAllowed =
ContentBlocking::ShouldAllowAccessFor(win, uri, aRejectedReason);
return NS_OK;
}

Expand Down
20 changes: 20 additions & 0 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2743,9 +2743,29 @@ nsresult nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) {
mContentListener->SetParentContentListener(parentURIListener);
}

// Inform windows when they're being removed from their parent.
if (!aParent) {
MaybeClearStorageAccessFlag();
}

return NS_OK;
}

void nsDocShell::MaybeClearStorageAccessFlag() {
if (mScriptGlobal) {
// Tell our window that the parent has now changed.
mScriptGlobal->ParentWindowChanged();

// Tell all of our children about the change recursively as well.
for (auto* childDocLoader : mChildList.ForwardRange()) {
nsCOMPtr<nsIDocShell> child = do_QueryObject(childDocLoader);
if (child) {
static_cast<nsDocShell*>(child.get())->MaybeClearStorageAccessFlag();
}
}
}
}

void nsDocShell::MaybeRestoreWindowName() {
if (!StaticPrefs::privacy_window_name_update_enabled()) {
return;
Expand Down
3 changes: 3 additions & 0 deletions docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ class nsDocShell final : public nsDocLoader,
nsDocShellLoadState* aLoadState,
mozilla::Maybe<uint32_t> aCacheKey = mozilla::Nothing());

// Clear the document's storage access flag if needed.
void MaybeClearStorageAccessFlag();

void MaybeRestoreWindowName();

void StoreWindowNameToSHEntries();
Expand Down
138 changes: 45 additions & 93 deletions dom/base/Document.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "nsPluginArray.h"
#include "nsMimeTypeArray.h"
#include "mozilla/Components.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/BodyExtractor.h"
Expand Down
6 changes: 3 additions & 3 deletions dom/base/ThirdPartyUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include "mozilla/Assertions.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/Logging.h"
#include "mozilla/MacroForEach.h"
#include "mozilla/Components.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/TextUtils.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/BrowsingContext.h"
Expand Down Expand Up @@ -512,8 +512,8 @@ ThirdPartyUtil::AnalyzeChannel(nsIChannel* aChannel, bool aNotify, nsIURI* aURI,
aRequireThirdPartyCheck ? result.contains(ThirdPartyAnalysis::IsForeign)
: true;
if (performStorageChecks &&
ShouldAllowAccessFor(aChannel, aURI ? aURI : uri.get(),
aRejectedReason)) {
ContentBlocking::ShouldAllowAccessFor(aChannel, aURI ? aURI : uri.get(),
aRejectedReason)) {
result += ThirdPartyAnalysis::IsStorageAccessPermissionGranted;
}

Expand Down
8 changes: 8 additions & 0 deletions dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ nsresult nsFrameLoader::ReallyStartLoadingInternal() {
return NS_OK;
}

if (GetDocShell()) {
// If we already have a docshell, ensure that the docshell's storage access
// flag is cleared.
GetDocShell()->MaybeClearStorageAccessFlag();
}

nsresult rv = MaybeCreateDocShell();
if (NS_FAILED(rv)) {
return rv;
Expand Down Expand Up @@ -1167,6 +1173,8 @@ void nsFrameLoader::Hide() {
return;
}

GetDocShell()->MaybeClearStorageAccessFlag();

nsCOMPtr<nsIContentViewer> contentViewer;
GetDocShell()->GetContentViewer(getter_AddRefs(contentViewer));
if (contentViewer) contentViewer->SetSticky(false);
Expand Down
10 changes: 7 additions & 3 deletions dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "nsISecureBrowserUI.h"
#include "nsIWebProgressListener.h"
#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/dom/AutoPrintEventDispatcher.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/BrowserChild.h"
Expand Down Expand Up @@ -51,7 +52,6 @@
#include "mozilla/dom/WindowFeatures.h" // WindowFeatures
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "nsBaseCommandController.h"
#include "nsError.h"
#include "nsICookieService.h"
Expand Down Expand Up @@ -1310,6 +1310,7 @@ nsGlobalWindowOuter::nsGlobalWindowOuter(uint64_t aWindowID)
mIsChrome(false),
mAllowScriptsToClose(false),
mTopLevelOuterContentWindow(false),
mStorageAccessPermissionGranted(false),
mDelayedPrintUntilAfterLoad(false),
mDelayedCloseForPrinting(false),
mShouldDelayPrintUntilAfterLoad(false),
Expand Down Expand Up @@ -2506,6 +2507,9 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,

PreloadLocalStorage();

mStorageAccessPermissionGranted = ContentBlocking::ShouldAllowAccessFor(
newInnerWindow, aDocument->GetDocumentURI(), nullptr);

// Do this here rather than in say the Document constructor, since
// we need a WindowContext available.
mDoc->InitUseCounters();
Expand Down Expand Up @@ -7134,8 +7138,8 @@ void nsGlobalWindowOuter::MaybeAllowStorageForOpenedWindow(nsIURI* aURI) {
aURI, doc->NodePrincipal()->OriginAttributesRef());

// We don't care when the asynchronous work finishes here.
Unused << StorageAccessAPIHelper::AllowAccessFor(
principal, GetBrowsingContext(), ContentBlockingNotifier::eOpener);
Unused << ContentBlocking::AllowAccessFor(principal, GetBrowsingContext(),
ContentBlockingNotifier::eOpener);
}

//*****************************************************************************
Expand Down
15 changes: 15 additions & 0 deletions dom/base/nsGlobalWindowOuter.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,

virtual bool IsInSyncOperation() override;

void ParentWindowChanged() {
// Reset our storage access permission flag when we get reparented.
mStorageAccessPermissionGranted = false;
}

public:
double GetInnerWidthOuter(mozilla::ErrorResult& aError);

Expand Down Expand Up @@ -871,6 +876,13 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,

bool IsInModalState();

bool IsStorageAccessPermissionGranted() const {
return mStorageAccessPermissionGranted;
}
void SetStorageAccessPermissionGranted(bool aStorageAccessPermissionGranted) {
mStorageAccessPermissionGranted = aStorageAccessPermissionGranted;
}

// Convenience functions for the many methods that need to scale
// from device to CSS pixels. This computes it with cached scale in
// PresContext which may be not recent information of the widget.
Expand Down Expand Up @@ -1087,6 +1099,9 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,

bool mTopLevelOuterContentWindow : 1;

// whether storage access has been granted to this frame.
bool mStorageAccessPermissionGranted : 1;

// Whether we've delayed a print until after load.
bool mDelayedPrintUntilAfterLoad : 1;
// Whether we've delayed a close() operation because there was a pending
Expand Down
2 changes: 2 additions & 0 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ mozilla::ipc::IPCResult BrowserChild::RecvLoadURL(
}
docShell->LoadURI(aLoadState, true);

nsDocShell::Cast(docShell)->MaybeClearStorageAccessFlag();

CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::URL, spec);
return IPC_OK();
}
Expand Down
6 changes: 3 additions & 3 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/BenchmarkStorageChild.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/FOGIPC.h"
#include "GMPServiceChild.h"
#include "Geolocation.h"
Expand Down Expand Up @@ -48,7 +49,6 @@
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "mozilla/TelemetryIPC.h"
#include "mozilla/Unused.h"
#include "mozilla/WebBrowserPersistDocumentChild.h"
Expand Down Expand Up @@ -3621,8 +3621,8 @@ mozilla::ipc::IPCResult ContentChild::RecvOnAllowAccessFor(
aReason) {
MOZ_ASSERT(!aContext.IsNull(), "Browsing context cannot be null");

StorageAccessAPIHelper::OnAllowAccessFor(
aContext.GetMaybeDiscarded(), aTrackingOrigin, aCookieBehavior, aReason);
ContentBlocking::OnAllowAccessFor(aContext.GetMaybeDiscarded(),
aTrackingOrigin, aCookieBehavior, aReason);

return IPC_OK();
}
Expand Down
29 changes: 15 additions & 14 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "gfxPlatformFontList.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/BenchmarkStorageParent.h"
#include "mozilla/ContentBlockingUserInteraction.h"
Expand Down Expand Up @@ -82,7 +83,6 @@
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/StorageAccessAPIHelper.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/Telemetry.h"
Expand Down Expand Up @@ -6406,17 +6406,18 @@ ContentParent::RecvStorageAccessPermissionGrantedForOrigin(
aReason.value());
}

StorageAccessAPIHelper::SaveAccessForOriginOnParentProcess(
ContentBlocking::SaveAccessForOriginOnParentProcess(
aTopLevelWindowId, aParentContext.get_canonical(), aTrackingPrincipal,
aAllowMode)
->Then(GetCurrentSerialEventTarget(), __func__,
[aResolver = std::move(aResolver)](
StorageAccessAPIHelper::ParentAccessGrantPromise::
ResolveOrRejectValue&& aValue) {
bool success =
aValue.IsResolve() && NS_SUCCEEDED(aValue.ResolveValue());
aResolver(success);
});
->Then(
GetCurrentSerialEventTarget(), __func__,
[aResolver = std::move(aResolver)](
ContentBlocking::ParentAccessGrantPromise::ResolveOrRejectValue&&
aValue) {
bool success =
aValue.IsResolve() && NS_SUCCEEDED(aValue.ResolveValue());
aResolver(success);
});
return IPC_OK();
}

Expand All @@ -6431,12 +6432,12 @@ mozilla::ipc::IPCResult ContentParent::RecvCompleteAllowAccessFor(
return IPC_OK();
}

StorageAccessAPIHelper::CompleteAllowAccessFor(
ContentBlocking::CompleteAllowAccessFor(
aParentContext.get_canonical(), aTopLevelWindowId, aTrackingPrincipal,
aTrackingOrigin, aCookieBehavior, aReason, nullptr)
->Then(GetCurrentSerialEventTarget(), __func__,
[aResolver = std::move(aResolver)](
StorageAccessAPIHelper::StorageAccessPermissionGrantPromise::
ContentBlocking::StorageAccessPermissionGrantPromise::
ResolveOrRejectValue&& aValue) {
Maybe<StorageAccessPromptChoices> choice;
if (aValue.IsResolve()) {
Expand Down Expand Up @@ -6470,8 +6471,8 @@ mozilla::ipc::IPCResult ContentParent::RecvTestCookiePermissionDecided(
nsCOMPtr<nsICookieJarSettings> cjs = wgp->CookieJarSettings();

Maybe<bool> result =
StorageAccessAPIHelper::CheckCookiesPermittedDecidesStorageAccessAPI(
cjs, aPrincipal);
ContentBlocking::CheckCookiesPermittedDecidesStorageAccessAPI(cjs,
aPrincipal);
aResolver(result);
return IPC_OK();
}
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ using mozilla::dom::PositionState from "mozilla/dom/MediaSession.h";
using mozilla::dom::ServiceWorkerShutdownState::Progress from "mozilla/dom/ServiceWorkerShutdownState.h";
using mozilla::ContentBlockingNotifier::StorageAccessPermissionGrantedReason from "mozilla/ContentBlockingNotifier.h";
using mozilla::ContentBlockingNotifier::BlockingDecision from "mozilla/ContentBlockingNotifier.h";
using mozilla::StorageAccessAPIHelper::StorageAccessPromptChoices from "mozilla/StorageAccessAPIHelper.h";
using mozilla::ContentBlocking::StorageAccessPromptChoices from "mozilla/ContentBlocking.h";
using JSActorMessageKind from "mozilla/dom/JSActor.h";
using JSActorMessageMeta from "mozilla/dom/PWindowGlobal.h";
using mozilla::PermissionDelegateHandler::DelegatedPermissionList from "mozilla/PermissionDelegateHandler.h";
Expand Down
6 changes: 6 additions & 0 deletions dom/ipc/WindowGlobalChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ WindowGlobalChild::RecvSaveStorageAccessPermissionGranted() {
inner->SaveStorageAccessPermissionGranted();
}

nsCOMPtr<nsPIDOMWindowOuter> outer =
nsPIDOMWindowOuter::GetFromCurrentInner(inner);
if (outer) {
nsGlobalWindowOuter::Cast(outer)->SetStorageAccessPermissionGranted(true);
}

return IPC_OK();
}

Expand Down
5 changes: 3 additions & 2 deletions dom/security/ReferrerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include "ReferrerInfo.h"

#include "mozilla/BasePrincipal.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ContentBlockingAllowList.h"
#include "mozilla/net/CookieJarSettings.h"
#include "mozilla/net/HttpBaseChannel.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/Telemetry.h"
#include "nsIWebProgressListener.h"
Expand Down Expand Up @@ -210,7 +210,8 @@ ReferrerPolicy ReferrerInfo::GetDefaultReferrerPolicy(nsIHttpChannel* aChannel,
if (XRE_IsParentProcess() && cjs->GetRejectThirdPartyContexts()) {
uint32_t rejectedReason = 0;
thirdPartyTrackerIsolated =
!ShouldAllowAccessFor(aChannel, aURI, &rejectedReason) &&
!ContentBlocking::ShouldAllowAccessFor(aChannel, aURI,
&rejectedReason) &&
rejectedReason !=
static_cast<uint32_t>(
nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN);
Expand Down
6 changes: 3 additions & 3 deletions image/ImageCacheKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/StoragePrincipalHelper.h"
Expand All @@ -16,7 +17,6 @@
#include "mozilla/dom/File.h"
#include "mozilla/dom/ServiceWorkerManager.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h"
#include "nsContentUtils.h"
#include "nsHashKeys.h"
#include "nsLayoutUtils.h"
Expand Down Expand Up @@ -153,8 +153,8 @@ nsCString ImageCacheKey::GetIsolationKey(Document* aDocument, nsIURI* aURI) {
// this point. The best approach here is to be conservative: if we are sure
// that the permission is granted, let's return 0. Otherwise, let's make a
// unique image cache per the top-level document eTLD+1.
if (!ApproximateAllowAccessForWithoutChannel(aDocument->GetInnerWindow(),
aURI)) {
if (!ContentBlocking::ApproximateAllowAccessForWithoutChannel(
aDocument->GetInnerWindow(), aURI)) {
// If we are here, the image is a 3rd-party resource loaded by a first-party
// context. We can just use the document's base domain as the key because it
// should be the same as the top-level document's base domain.
Expand Down
5 changes: 3 additions & 2 deletions netwerk/cookie/CookieCommons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "CookieCommons.h"
#include "CookieLogging.h"
#include "CookieService.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/ConsoleReportCollector.h"
#include "mozilla/ContentBlockingNotifier.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/StorageAccess.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/nsMixedContentBlocker.h"
#include "mozilla/net/CookieJarSettings.h"
Expand Down Expand Up @@ -386,7 +386,8 @@ already_AddRefed<Cookie> CookieCommons::CreateCookieFromDocument(
if (aDocument->CookieJarSettings()->GetLimitForeignContexts() &&
!aHasExistingCookiesLambda(baseDomain,
storagePrincipal->OriginAttributesRef()) &&
!ShouldAllowAccessFor(innerWindow, principalURI, &dummyRejectedReason)) {
!ContentBlocking::ShouldAllowAccessFor(innerWindow, principalURI,
&dummyRejectedReason)) {
return nullptr;
}

Expand Down
Loading

0 comments on commit a0f6973

Please sign in to comment.