Bug 1732052: Remove pref privacy.file_unique_origin r=ckerschb,necko-reviewers,dragana

Differential Revision: https://phabricator.services.mozilla.com/D126898
This commit is contained in:
Niklas Goegge 2021-10-19 12:57:34 +00:00
parent ed2a063156
commit 1244799959
6 changed files with 1 additions and 144 deletions

View File

@ -1,6 +1,5 @@
<!DOCTYPE html>
<meta charset="utf-8">
<h3>Set <code>privacy.file_unique_origin</code> to false when testing this.</h3>
<script>
fetch("./url.url")
</script>

View File

@ -1,2 +1,2 @@
load 1577196.html
pref(privacy.file_unique_origin,false) load 1664514.html
load 1664514.html

View File

@ -3,108 +3,6 @@
* 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);
let dir_a = parent.clone();
dir_a.append("a");
dir_a.create(Ci.nsIFile.DIRECTORY_TYPE, 0o700);
let page_a = dir_a.clone();
page_a.append("empty.html");
page_a.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
let url_a = Services.io.newFileURI(page_a);
let worker = dir_a.clone();
worker.append("worker.js");
let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
Ci.nsIFileOutputStream
);
stream.init(
worker,
0x02 | 0x08 | 0x20, // write, create, truncate
0o666,
0
);
stream.write(WORKER_BODY, WORKER_BODY.length);
stream.close();
let url_worker = Services.io.newFileURI(worker);
let dir_b = parent.clone();
dir_b.append("b");
dir_b.create(Ci.nsIFile.DIRECTORY_TYPE, 0o700);
let page_b = dir_b.clone();
page_b.append("empty.html");
page_b.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
let url_b = Services.io.newFileURI(page_b);
let tab = BrowserTestUtils.addTab(gBrowser, url_a.spec);
gBrowser.selectedTab = tab;
let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
await SpecialPowers.spawn(browser, [url_worker.spec], function(spec) {
return new content.Promise((resolve, reject) => {
let w = new content.window.Worker(spec);
w.onerror = _ => {
reject();
};
w.onmessage = _ => {
resolve();
};
});
});
ok(true, "The worker is loaded when the script is on the same directory.");
BrowserTestUtils.removeTab(tab);
tab = BrowserTestUtils.addTab(gBrowser, url_b.spec);
gBrowser.selectedTab = tab;
browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
await SpecialPowers.spawn(browser, [url_worker.spec], function(spec) {
return new content.Promise((resolve, reject) => {
let w = new content.window.Worker(spec);
w.onerror = _ => {
resolve();
};
w.onmessage = _ => {
reject();
};
});
});
ok(
true,
"The worker is not loaded when the script is on a different directory."
);
BrowserTestUtils.removeTab(tab);
info("Removing the tmp directory.");
parent.remove(true);
});
const EMPTY_URL = "/browser/dom/workers/test/empty.html";
const WORKER_URL = "/browser/dom/workers/test/empty_worker.js";

View File

@ -10258,11 +10258,6 @@
# Prefs starting with "privacy."
#---------------------------------------------------------------------------
- name: privacy.file_unique_origin
type: bool
value: true
mirror: always
- name: privacy.fuzzyfox.clockgrainus
type: RelaxedAtomicUint32
value: 100

View File

@ -2538,37 +2538,6 @@ bool NS_RelaxStrictFileOriginPolicy(nsIURI* aTargetURI, nsIURI* aSourceURI,
return false;
}
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;
}
}
return false;
}

View File

@ -4,10 +4,6 @@
"use strict";
add_task(async () => {
await SpecialPowers.pushPrefEnv({
set: [["privacy.file_unique_origin", false]],
});
const FILE_PAGE = Services.io.newFileURI(
new FileUtils.File(getTestFilePath("dummy.html"))
).spec;