Bug 1554781 - Part 1: Lift the check for whether we have a third-party tracking window out of GetParentPrincipalAndTrackingOrigin(); r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 28 May 2019 12:06:37 +0000
changeset 475942 2191d21821d5792731da4c99c96fb476e31ca5f6
parent 475941 e6425d92b052edac5c645ac5c1422c8393d0f604
child 475943 452b8c9f9a1349f44e523711f2f0f32dc927ba3c
push id86554
push usereakhgari@mozilla.com
push dateTue, 28 May 2019 20:48:16 +0000
treeherderautoland@ece4def4fd82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1554781
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1554781 - Part 1: Lift the check for whether we have a third-party tracking window out of GetParentPrincipalAndTrackingOrigin(); r=baku Differential Revision: https://phabricator.services.mozilla.com/D32765
toolkit/components/antitracking/AntiTrackingCommon.cpp
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -68,21 +68,16 @@ namespace {
 
 UniquePtr<nsTArray<AntiTrackingCommon::AntiTrackingSettingsChangedCallback>>
     gSettingsChangedCallbacks;
 
 bool GetParentPrincipalAndTrackingOrigin(
     nsGlobalWindowInner* a3rdPartyTrackingWindow,
     nsIPrincipal** aTopLevelStoragePrincipal, nsACString& aTrackingOrigin,
     nsIURI** aTrackingURI, nsIPrincipal** aTrackingPrincipal) {
-  if (!nsContentUtils::IsThirdPartyTrackingResourceWindow(
-          a3rdPartyTrackingWindow)) {
-    return false;
-  }
-
   Document* doc = a3rdPartyTrackingWindow->GetDocument();
   // Make sure storage access isn't disabled
   if (doc && (doc->StorageAccessSandboxed() ||
               nsContentUtils::IsInPrivateBrowsing(doc))) {
     return false;
   }
 
   // Now we need the principal and the origin of the parent window.
@@ -781,21 +776,28 @@ AntiTrackingCommon::AddFirstPartyStorage
   LOG(("Adding a first-party storage exception for %s...",
        PromiseFlatCString(origin).get()));
 
   Document* parentDoc = aParentWindow->GetExtantDoc();
   if (!parentDoc) {
     LOG(("Parent window has no doc"));
     return StorageAccessGrantPromise::CreateAndReject(false, __func__);
   }
+  int32_t behavior = parentDoc->CookieSettings()->GetCookieBehavior();
+
+  MOZ_ASSERT(
+      behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
+      behavior ==
+          nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
+
   if (!parentDoc->CookieSettings()->GetRejectThirdPartyTrackers()) {
     LOG(
         ("Disabled by network.cookie.cookieBehavior pref (%d), bailing out "
          "early",
-         parentDoc->CookieSettings()->GetCookieBehavior()));
+         behavior));
     return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
   }
 
   if (CheckContentBlockingAllowList(aParentWindow)) {
     return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
   }
 
   nsCOMPtr<nsIPrincipal> topLevelStoragePrincipal;
@@ -825,25 +827,48 @@ AntiTrackingCommon::AddFirstPartyStorage
       return StorageAccessGrantPromise::CreateAndReject(false, __func__);
     }
     topLevelStoragePrincipal = parentWindow->GetPrincipal();
     if (NS_WARN_IF(!topLevelStoragePrincipal)) {
       LOG(("Top-level storage area principal not found, bailing out early"));
       return StorageAccessGrantPromise::CreateAndReject(false, __func__);
     }
 
-    // We are a 3rd party source.
-  } else if (!GetParentPrincipalAndTrackingOrigin(
-                 parentWindow, getter_AddRefs(topLevelStoragePrincipal),
-                 trackingOrigin, getter_AddRefs(trackingURI),
-                 getter_AddRefs(trackingPrincipal))) {
-    LOG(
-        ("Error while computing the parent principal and tracking origin, "
-         "bailing out early"));
-    return StorageAccessGrantPromise::CreateAndReject(false, __func__);
+  } else {
+    // We should be a 3rd party source.
+    bool isThirdParty = false;
+    if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) {
+      isThirdParty =
+          nsContentUtils::IsThirdPartyTrackingResourceWindow(parentWindow);
+    } else if (behavior == nsICookieService::
+                               BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) {
+      isThirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(
+          parentWindow, nullptr, nullptr);
+    }
+
+    if (!isThirdParty) {
+      if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER) {
+        LOG(("Our window isn't a third-party tracking window"));
+      } else if (behavior ==
+                 nsICookieService::
+                     BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) {
+        LOG(("Our window isn't a third-party window"));
+      }
+      return StorageAccessGrantPromise::CreateAndReject(false, __func__);
+    }
+
+    if (!GetParentPrincipalAndTrackingOrigin(
+            parentWindow, getter_AddRefs(topLevelStoragePrincipal),
+            trackingOrigin, getter_AddRefs(trackingURI),
+            getter_AddRefs(trackingPrincipal))) {
+      LOG(
+          ("Error while computing the parent principal and tracking origin, "
+           "bailing out early"));
+      return StorageAccessGrantPromise::CreateAndReject(false, __func__);
+    }
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> topOuterWindow = outerParentWindow->GetTop();
   nsGlobalWindowOuter* topWindow = nsGlobalWindowOuter::Cast(topOuterWindow);
   if (NS_WARN_IF(!topWindow)) {
     LOG(("No top outer window."));
     return StorageAccessGrantPromise::CreateAndReject(false, __func__);
   }