[TabGuard] Fixed regression in about:blank handling (thanks NDevTK for reporting).

This commit is contained in:
hackademix 2022-08-30 13:56:28 +02:00
parent 651e476650
commit c22eafc35b
1 changed files with 16 additions and 3 deletions

View File

@ -116,15 +116,28 @@ var TabGuard = (() => {
tab._externalUrl = tab.url; tab._externalUrl = tab.url;
tab._isExplicitOrigin = true; tab._isExplicitOrigin = true;
try { try {
tab.url = await browser.tabs.executeScript(tab.id, { tab.url = await browser.tabs.executeScript(tab.id, {
runAt: "document_start", runAt: "document_start",
code: "window.origin === 'null' ? window.location.href : window.origin" code: "window.origin === 'null' ? window.location.href : window.origin"
}); });
} catch (e) { } catch (e) {
// We don't have permissions to run in this tab, probably because it has been left empty.
debug(e); debug(e);
} }
debug(`Real origin for ${tab._externalUrl} (tab ${tab.id}) is ${tab.url}.`); // If it's about:blank and it has got an opener, let's assume the opener
if (!ns.policy.can(tab.url, "script")) return; // is the real origin and it's using the empty tab to run scripts.
if (tab.url === "about:blank") {
if (tab.openerTabId > 0) {
let openerTab = TabCache.get(tab.openerTabId);
if (openerTab) {
tab.url = openerTab.url;
}
}
}
if (tab.url !== "about:blank") {
debug(`Real origin for ${tab._externalUrl} (tab ${tab.id}) is ${tab.url}.`);
if (!ns.policy.can(tab.url, "script")) return;
}
} }
suspiciousDomains.push(getDomain(tab.url)); suspiciousDomains.push(getDomain(tab.url));
})); }));