Bug 1642006 - Part 1: detect tracking redirection; r=baku
authorLiang-Heng Chen <xeonchen@gmail.com>
Thu, 04 Jun 2020 21:05:35 +0000
changeset 534020 d681a17e123add8f742fdae2e2d2d7aafacc31db
parent 534019 1b7929bcdad384af472dea00a279256461c7d503
child 534021 3c66e591e1e502926dbe33d0a8a56fd7564bbe42
push id37481
push userncsoregi@mozilla.com
push dateFri, 05 Jun 2020 04:39:26 +0000
treeherdermozilla-central@fecffba489bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1642006
milestone79.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 1642006 - Part 1: detect tracking redirection; r=baku Differential Revision: https://phabricator.services.mozilla.com/D78272
toolkit/components/antitracking/DynamicFpiRedirectHeuristic.cpp
--- a/toolkit/components/antitracking/DynamicFpiRedirectHeuristic.cpp
+++ b/toolkit/components/antitracking/DynamicFpiRedirectHeuristic.cpp
@@ -149,16 +149,47 @@ void AddConsoleReport(nsIChannel* aNewCh
                                     NS_ConvertUTF8toUTF16(aOldOrigin)};
 
   httpChannel->AddConsoleReport(
       nsIScriptError::warningFlag, ANTITRACKING_CONSOLE_CATEGORY,
       nsContentUtils::eNECKO_PROPERTIES, uri, 0, 0,
       NS_LITERAL_CSTRING("CookieAllowedForFpiByHeuristic"), params);
 }
 
+bool ShouldRedirectHeuristicApplyTrackingResource(nsIChannel* aOldChannel,
+                                                  nsIURI* aOldURI,
+                                                  nsIChannel* aNewChannel,
+                                                  nsIURI* aNewURI) {
+  nsCOMPtr<nsIClassifiedChannel> classifiedOldChannel =
+      do_QueryInterface(aOldChannel);
+  if (!classifiedOldChannel) {
+    LOG_SPEC2(("Ignoring redirect for %s to %s because there is not "
+               "nsIClassifiedChannel interface",
+               _spec1, _spec2),
+              aOldURI, aNewURI);
+    return false;
+  }
+
+  // We're looking at the first-party classification flags because we're
+  // interested in first-party redirects.
+  uint32_t oldClassificationFlags =
+      classifiedOldChannel->GetFirstPartyClassificationFlags();
+
+  if (net::UrlClassifierCommon::IsTrackingClassificationFlag(
+          oldClassificationFlags)) {
+    // This is a redirect from tracking.
+    LOG_SPEC2(("Ignoring redirect for %s to %s because it's from tracking ",
+               _spec1, _spec2),
+              aOldURI, aNewURI);
+    return false;
+  }
+
+  return true;
+}
+
 }  // namespace
 
 void DynamicFpiRedirectHeuristic(nsIChannel* aOldChannel, nsIURI* aOldURI,
                                  nsIChannel* aNewChannel, nsIURI* aNewURI) {
   MOZ_ASSERT(aOldChannel);
   MOZ_ASSERT(aOldURI);
   MOZ_ASSERT(aNewChannel);
   MOZ_ASSERT(aNewURI);
@@ -240,16 +271,24 @@ void DynamicFpiRedirectHeuristic(nsIChan
     return;
   }
 
   if (oldPrincipal->Equals(newPrincipal)) {
     LOG(("No permission needed for same principals."));
     return;
   }
 
+  if (!ShouldRedirectHeuristicApplyTrackingResource(aOldChannel, aOldURI,
+                                                    aNewChannel, aNewURI)) {
+    LOG_SPEC2(("Ignoring redirect for %s to %s because tracking test failed",
+               _spec1, _spec2),
+              aOldURI, aNewURI);
+    return;
+  }
+
   if (!ContentBlockingUserInteraction::Exists(oldPrincipal) ||
       !ContentBlockingUserInteraction::Exists(newPrincipal)) {
     LOG_SPEC2(("Ignoring redirect for %s to %s because no user-interaction on "
                "both pages",
                _spec1, _spec2),
               aOldURI, aNewURI);
     return;
   }