Skip to content

Commit cb650e7

Browse files
committed
[Gecko] Improved freezing/unfreezing for file:// documents (thanks Security Research Labs for report).
1 parent c92c49a commit cb650e7

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/content/staticNS.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180

181181
if (DocumentFreezer.isFrozen) {
182182
if (!this.canScript) {
183-
DocumentFreezer.unfreezeLive();
183+
if (location.protocol.startsWith("http")) {
184+
DocumentFreezer.unfreezeLive();
185+
}
184186
} else {
185187
DocumentFreezer.unfreezeAutoReload();
186188
}

src/content/syncFetchPolicy.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (/^(?:file|ftp):$/.test(location.protocol)) {
2929
ns.pendingSyncFetchPolicy = false;
3030
ns.syncFetchPolicy = () => {};
3131

32-
let url = document.URL;
32+
const url = document.URL;
3333

3434
// Here we've got no CSP header yet (file: or ftp: URL), we need one
3535
// injected in the DOM as soon as possible.
@@ -77,6 +77,18 @@ if (/^(?:file|ftp):$/.test(location.protocol)) {
7777
&& document.readyState !== "complete";
7878

7979
if (mustFreeze) {
80+
const normalizeDir = e => {
81+
// Chromium does this automatically. We need it to understand we're a directory earlier and allow browser UI scripts.
82+
if (document.baseURI === `${url}/`) {
83+
if (e) {
84+
document.removeEventListener(e.type, normalizeDir);
85+
e.stopImmediatePropagation();
86+
}
87+
window.stop();
88+
location.replace(document.baseURI);
89+
}
90+
}
91+
normalizeDir();
8092
// Mozilla has already parsed the <head> element, we must take extra steps...
8193
try {
8294
DocumentFreezer.freeze();
@@ -86,17 +98,9 @@ if (/^(?:file|ftp):$/.test(location.protocol)) {
8698
debug("Readystate: %s, suppressedScripts = %s, canScript = %s", document.readyState, DocumentFreezer.suppressedScripts, ns.canScript);
8799

88100
if (!ns.canScript) {
89-
queueMicrotask(() => DocumentFreezer.unfreezeLive());
90-
let normalizeDir = e => {
91-
// Chromium does this automatically. We need it to understand we're a directory earlier and allow browser UI scripts.
92-
if (document.baseURI === document.URL + "/") {
93-
if (e) {
94-
document.removeEventListener(e.type, normalizeDir);
95-
e.stopImmediatePropagation();
96-
}
97-
window.stop();
98-
location.replace(document.baseURI);
99-
}
101+
if (url.endsWith("/")) {
102+
DocumentFreezer.unfreezeLive();
103+
return;
100104
}
101105
if (DocumentFreezer.firedDOMContentLoaded) {
102106
normalizeDir();

src/nscl

0 commit comments

Comments
 (0)