From 363e542f6e086ccddffb14144f8e15100341d67c Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 24 Aug 2018 18:54:10 -0400 Subject: [PATCH] Bug 1486092 - Part 2: Make the reject tracker cookie behavior also depend on the browser.contentblocking.enabled pref; r=baku The semantics implemented are as follows: the feature requires this new pref to also be set to true, otherwise cookies from trackers will be accepted. --- dom/base/nsDocument.cpp | 3 ++- dom/workers/RuntimeService.cpp | 6 +++-- .../antitracking/AntiTrackingCommon.cpp | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index c5c55ce645b9..ad29695ee89b 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -12653,7 +12653,8 @@ void nsIDocument::MaybeAllowStorageForOpener() { if (StaticPrefs::network_cookie_cookieBehavior() != - nsICookieService::BEHAVIOR_REJECT_TRACKER) { + nsICookieService::BEHAVIOR_REJECT_TRACKER || + !StaticPrefs::browser_contentblocking_enabled()) { return; } diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index ddd7bec79040..f6bdda1d9bf6 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -2271,7 +2271,8 @@ RuntimeService::PropagateFirstPartyStorageAccessGranted(nsPIDOMWindowInner* aWin AssertIsOnMainThread(); MOZ_ASSERT(aWindow); MOZ_ASSERT(StaticPrefs::network_cookie_cookieBehavior() == - nsICookieService::BEHAVIOR_REJECT_TRACKER); + nsICookieService::BEHAVIOR_REJECT_TRACKER && + StaticPrefs::browser_contentblocking_enabled()); nsTArray workers; GetWorkersForWindow(aWindow, workers); @@ -2885,7 +2886,8 @@ PropagateFirstPartyStorageAccessGrantedToWorkers(nsPIDOMWindowInner* aWindow) { AssertIsOnMainThread(); MOZ_ASSERT(StaticPrefs::network_cookie_cookieBehavior() == - nsICookieService::BEHAVIOR_REJECT_TRACKER); + nsICookieService::BEHAVIOR_REJECT_TRACKER && + StaticPrefs::browser_contentblocking_enabled()); RuntimeService* runtime = RuntimeService::GetService(); if (runtime) { diff --git a/toolkit/components/antitracking/AntiTrackingCommon.cpp b/toolkit/components/antitracking/AntiTrackingCommon.cpp index f0a69331acb0..cf2fa60d936d 100644 --- a/toolkit/components/antitracking/AntiTrackingCommon.cpp +++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp @@ -150,6 +150,11 @@ AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigi return StorageAccessGrantPromise::CreateAndResolve(true, __func__); } + if (!StaticPrefs::browser_contentblocking_enabled()) { + LOG(("The content blocking pref has been disabled, bail out early")); + return StorageAccessGrantPromise::CreateAndResolve(true, __func__); + } + nsCOMPtr topLevelStoragePrincipal; nsAutoCString trackingOrigin; @@ -324,6 +329,14 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* aWin } MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER); + + // Now, we have to also honour the Content Blocking pref. + if (!StaticPrefs::browser_contentblocking_enabled()) { + LOG(("The content blocking pref has been disabled, bail out early by " + "by pretending our window isn't a tracking window")); + return true; + } + if (!nsContentUtils::IsTrackingResourceWindow(aWindow)) { LOG(("Our window isn't a tracking window")); return true; @@ -484,6 +497,13 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsIHttpChannel* aChannel MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER); + // Now, we have to also honour the Content Blocking pref. + if (!StaticPrefs::browser_contentblocking_enabled()) { + LOG(("The content blocking pref has been disabled, bail out early by " + "pretending our channel isn't a tracking channel")); + return true; + } + nsIPrincipal* parentPrincipal = loadInfo->TopLevelStorageAreaPrincipal(); if (!parentPrincipal) { LOG(("No top-level storage area principal at hand")); @@ -591,6 +611,12 @@ AntiTrackingCommon::MaybeIsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* return true; } + // Now, we have to also honour the Content Blocking pref. + if (!StaticPrefs::browser_contentblocking_enabled()) { + LOG(("The content blocking pref has been disabled, bail out early")); + return true; + } + if (!nsContentUtils::IsThirdPartyWindowOrChannel(aFirstPartyWindow, nullptr, aURI)) { LOG(("Our window isn't a third-party window"));