Handle edge-case policy retrieval for file:// pages loaded by session restore on startup and alike.
This commit is contained in:
parent
a9a85a5c22
commit
e3c09d4dc0
|
@ -142,9 +142,20 @@
|
||||||
|
|
||||||
fetchChildPolicy({url, contextUrl}, sender) {
|
fetchChildPolicy({url, contextUrl}, sender) {
|
||||||
let {tab, frameId} = sender;
|
let {tab, frameId} = sender;
|
||||||
|
let policy = ns.policy;
|
||||||
|
if (!policy) {
|
||||||
|
console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing);
|
||||||
|
return {
|
||||||
|
permissions: new Permissions(Permissions.DEFAULT).dry(),
|
||||||
|
unrestricted: false,
|
||||||
|
cascaded: false,
|
||||||
|
fallback: true
|
||||||
|
};
|
||||||
|
}
|
||||||
let topUrl = frameId === 0 ? contextUrl : tab && (tab.url || TabCache.get(tab.id));
|
let topUrl = frameId === 0 ? contextUrl : tab && (tab.url || TabCache.get(tab.id));
|
||||||
let policy = !Sites.isInternal(url) && ns.isEnforced(tab ? tab.id : -1)
|
if (Sites.isInternal(url) || !ns.isEnforced(tab ? tab.id : -1)) {
|
||||||
? ns.policy : null;
|
policy = null;
|
||||||
|
}
|
||||||
|
|
||||||
let permissions, unrestricted, cascaded;
|
let permissions, unrestricted, cascaded;
|
||||||
if (policy) {
|
if (policy) {
|
||||||
|
@ -156,7 +167,7 @@
|
||||||
permissions = perms.dry();
|
permissions = perms.dry();
|
||||||
} else {
|
} else {
|
||||||
// otherwise either internal URL or unrestricted
|
// otherwise either internal URL or unrestricted
|
||||||
permissions = new Permissions(Permissions.ALL);
|
permissions = new Permissions(Permissions.ALL).dry();
|
||||||
unrestricted = true;
|
unrestricted = true;
|
||||||
cascaded = false;
|
cascaded = false;
|
||||||
}
|
}
|
||||||
|
@ -198,6 +209,7 @@
|
||||||
policy: null,
|
policy: null,
|
||||||
local: null,
|
local: null,
|
||||||
sync: null,
|
sync: null,
|
||||||
|
initializing: null,
|
||||||
unrestrictedTabs: new Set(),
|
unrestrictedTabs: new Set(),
|
||||||
isEnforced(tabId = -1) {
|
isEnforced(tabId = -1) {
|
||||||
return this.policy.enforced && (tabId === -1 || !this.unrestrictedTabs.has(tabId));
|
return this.policy.enforced && (tabId === -1 || !this.unrestrictedTabs.has(tabId));
|
||||||
|
@ -210,10 +222,8 @@
|
||||||
start() {
|
start() {
|
||||||
if (this.running) return;
|
if (this.running) return;
|
||||||
this.running = true;
|
this.running = true;
|
||||||
|
|
||||||
browser.runtime.onSyncMessage.addListener(onSyncMessage);
|
browser.runtime.onSyncMessage.addListener(onSyncMessage);
|
||||||
|
deferWebTraffic(this.initalizing = init(),
|
||||||
deferWebTraffic(init(),
|
|
||||||
async () => {
|
async () => {
|
||||||
Commands.install();
|
Commands.install();
|
||||||
|
|
||||||
|
|
|
@ -34,18 +34,47 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchPolicy() {
|
fetchPolicy() {
|
||||||
|
debug(`Fetching policy from document %s, readyState %s, content %s`,
|
||||||
|
document.URL, document.readyState, document.documentElement.outerHTML);
|
||||||
|
|
||||||
let url = document.URL;
|
let url = document.URL;
|
||||||
|
|
||||||
|
if (url.startsWith("file:")) {
|
||||||
|
let cookie = "noscript.startupFileReloaded=true";
|
||||||
|
if (!document.cookie.split(/\s*;\s*/).includes(cookie)) {
|
||||||
|
stop();
|
||||||
|
setTimeout(() => {
|
||||||
|
document.cookie = cookie;
|
||||||
|
location.reload();
|
||||||
|
}, 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let policy = browser.runtime.sendSyncMessage(
|
let policy = browser.runtime.sendSyncMessage(
|
||||||
{id: "fetchPolicy", url, contextUrl: document.URL});
|
{id: "fetchPolicy", url, contextUrl: url});
|
||||||
|
|
||||||
|
debug("Fetched %o, readyState %s", policy, document.readyState);
|
||||||
if (!policy) {
|
if (!policy) {
|
||||||
debug(`No answer to fetchPolicy message. This should not be happening.`);
|
debug("Could not fetch policy!");
|
||||||
|
if (url.startsWith("file:") && !sessionStorage.__noScriptFallbackReload__) {
|
||||||
|
sessionStorage.__noScriptFallbackReload__ = "true";
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
// let's try asynchronously
|
||||||
|
(async () => {
|
||||||
|
this.setup(await Messages.send("fetchPolicy", {url, contextUrl: url}));
|
||||||
|
})();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
|
} else if (policy.fallback) {
|
||||||
|
location.reload();
|
||||||
}
|
}
|
||||||
this.setup(policy);
|
this.setup(policy);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(policy) {
|
setup(policy) {
|
||||||
|
debug("%s, %s, %o", document.URL, document.readyState, policy);
|
||||||
this.policy = policy;
|
this.policy = policy;
|
||||||
|
|
||||||
if (!policy.permissions || policy.unrestricted) {
|
if (!policy.permissions || policy.unrestricted) {
|
||||||
|
|
Loading…
Reference in New Issue