Skip to content

Commit d88a0cf

Browse files
committed
Fixed infinite reload loops on scripting permissions mismatches.
1 parent 391c8b4 commit d88a0cf

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/bg/RequestGuard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ var RequestGuard = (() => {
269269
let records = TabStatus.map.get(tabId);
270270
let noscriptFrames = records && records.noscriptFrames;
271271
let canScript = !(noscriptFrames && noscriptFrames[sender.frameId]);
272-
let shouldScript = ns.isEnforced(tabId) && ns.policy.can(url, "script");
272+
let shouldScript = !ns.isEnforced(tabId) || ns.policy.can(url, "script");
273273
debug("Frame %s %s of %o, canScript: %s, shouldScript: %s", frameId, url, noscriptFrames, canScript, shouldScript);
274274
return {canScript, shouldScript};
275275
}

src/content/content.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ let notifyPage = () => {
8787
}
8888

8989
var queryingCanScript = false;
90-
var caps = {};
90+
91+
function reload(noCache = false) {
92+
init = () => {};
93+
location.reload(noCache);
94+
}
9195

9296
async function init(oldPage = false) {
9397
if (queryingCanScript) return;
94-
if (document.URL === "about:blank") {
98+
if (!document.URL.startsWith("http")) {
9599
return;
96100
}
97101
queryingCanScript = true;
@@ -105,20 +109,21 @@ async function init(oldPage = false) {
105109
if (canScript) {
106110
if (oldPage) {
107111
probe();
108-
setTimeout(() => init(), 100);
112+
setTimeout(() => init(), 200);
109113
return;
110114
}
111115
if (!shouldScript) {
112116
// Something wrong: scripts can run, permissions say they shouldn't.
113117
// Was webRequest bypassed by caching/session restore/service workers?
118+
window.stop();
114119
let noCache = !!navigator.serviceWorker.controller;
115120
if (noCache) {
116121
for (let r of await navigator.serviceWorker.getRegistrations()) {
117122
await r.unregister();
118123
}
119124
}
120125
debug("Reloading %s (%s)", document.URL, noCache ? "no cache" : "cached");
121-
location.reload(noCache);
126+
reload(noCache);
122127
return;
123128
}
124129
}
@@ -129,7 +134,8 @@ async function init(oldPage = false) {
129134
if (!oldPage &&
130135
/Receiving end does not exist/.test(e.message)) {
131136
// probably startup and bg page not ready yet, hence no CSP: reload!
132-
location.reload(false);
137+
debug("Reloading", document.URL);
138+
reload();
133139
} else {
134140
setTimeout(() => init(oldPage), 100);
135141
}
@@ -162,4 +168,4 @@ async function init(oldPage = false) {
162168
// document.write("<plaintext>");
163169
}
164170
notifyPage() || addEventListener("pageshow", notifyPage);
165-
};
171+
}

0 commit comments

Comments
 (0)