Bug 1558299 - Add a pref to treat File: URLs as unique origins, r=ckerschb
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 05 Jul 2019 09:16:06 +0000
changeset 541146 2ad059cc9e7835a1cf2a6f34be1c9e3f8eb7d7a4
parent 541145 556d26e5029b8d5f2c4cf409718011bffc7e3c7f
child 541147 5d766b1b196d4608fc9a6d8df0d5d5550b3eea5f
push id11533
push userarchaeopteryx@coole-files.de
push dateMon, 08 Jul 2019 18:18:03 +0000
treeherdermozilla-beta@f4452e031aed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1558299
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 1558299 - Add a pref to treat File: URLs as unique origins, r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D36920
dom/workers/test/browser_fileURL.js
modules/libpref/init/StaticPrefList.h
netwerk/base/nsNetUtil.cpp
--- a/dom/workers/test/browser_fileURL.js
+++ b/dom/workers/test/browser_fileURL.js
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const WORKER_BODY = "postMessage(42);\n";
 
 // file:// tests.
 add_task(async function() {
+  await SpecialPowers.pushPrefEnv({set: [["privacy.file_unique_origin", false]]});
+
   info("Creating the tmp directory.");
   let parent = Cc["@mozilla.org/file/directory_service;1"]
     .getService(Ci.nsIDirectoryService)
     .QueryInterface(Ci.nsIProperties)
     .get("TmpD", Ci.nsIFile);
   parent.append("worker-dir-test");
   parent.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o700);
 
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -6853,16 +6853,23 @@ VARCACHE_PREF(
    print_font_variations_as_paths,
   RelaxedAtomicBool, true
 )
 
 //---------------------------------------------------------------------------
 // Prefs starting with "privacy."
 //---------------------------------------------------------------------------
 
+VARCACHE_PREF(
+  Live,
+  "privacy.file_unique_origin",
+   privacy_file_unique_origin,
+  bool, true
+)
+
 // Annotate trackers using the strict list. If set to false, the basic list will
 // be used instead.
 #ifdef EARLY_BETA_OR_EARLIER
 #define PREF_VALUE true
 #else
 #define PREF_VALUE false
 #endif
 VARCACHE_PREF(
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2488,43 +2488,45 @@ bool NS_RelaxStrictFileOriginPolicy(nsIU
 #ifndef MOZ_WIDGET_ANDROID
       NS_FAILED(sourceFile->Normalize()) ||
 #endif
       (!aAllowDirectoryTarget &&
        (NS_FAILED(targetFile->IsDirectory(&targetIsDir)) || targetIsDir))) {
     return false;
   }
 
-  //
-  // If the file to be loaded is in a subdirectory of the source
-  // (or same-dir if source is not a directory) then it will
-  // inherit its source principal and be scriptable by that source.
-  //
-  bool sourceIsDir;
-  bool allowed = false;
-  nsresult rv = sourceFile->IsDirectory(&sourceIsDir);
-  if (NS_SUCCEEDED(rv) && sourceIsDir) {
-    rv = sourceFile->Contains(targetFile, &allowed);
-  } else {
-    nsCOMPtr<nsIFile> sourceParent;
-    rv = sourceFile->GetParent(getter_AddRefs(sourceParent));
-    if (NS_SUCCEEDED(rv) && sourceParent) {
-      rv = sourceParent->Equals(targetFile, &allowed);
-      if (NS_FAILED(rv) || !allowed) {
-        rv = sourceParent->Contains(targetFile, &allowed);
-      } else {
-        MOZ_ASSERT(aAllowDirectoryTarget,
-                   "sourceFile->Parent == targetFile, but targetFile "
-                   "should've been disallowed if it is a directory");
+  if (!StaticPrefs::privacy_file_unique_origin()) {
+    //
+    // If the file to be loaded is in a subdirectory of the source
+    // (or same-dir if source is not a directory) then it will
+    // inherit its source principal and be scriptable by that source.
+    //
+    bool sourceIsDir;
+    bool allowed = false;
+    nsresult rv = sourceFile->IsDirectory(&sourceIsDir);
+    if (NS_SUCCEEDED(rv) && sourceIsDir) {
+      rv = sourceFile->Contains(targetFile, &allowed);
+    } else {
+      nsCOMPtr<nsIFile> sourceParent;
+      rv = sourceFile->GetParent(getter_AddRefs(sourceParent));
+      if (NS_SUCCEEDED(rv) && sourceParent) {
+        rv = sourceParent->Equals(targetFile, &allowed);
+        if (NS_FAILED(rv) || !allowed) {
+          rv = sourceParent->Contains(targetFile, &allowed);
+        } else {
+          MOZ_ASSERT(aAllowDirectoryTarget,
+                     "sourceFile->Parent == targetFile, but targetFile "
+                     "should've been disallowed if it is a directory");
+        }
       }
     }
-  }
-
-  if (NS_SUCCEEDED(rv) && allowed) {
-    return true;
+
+    if (NS_SUCCEEDED(rv) && allowed) {
+      return true;
+    }
   }
 
   return false;
 }
 
 bool NS_IsInternalSameURIRedirect(nsIChannel* aOldChannel,
                                   nsIChannel* aNewChannel, uint32_t aFlags) {
   if (!(aFlags & nsIChannelEventSink::REDIRECT_INTERNAL)) {