From c22eafc35bfcc379e9323cae67c924dfa1830684 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 30 Aug 2022 13:56:28 +0200 Subject: [PATCH] [TabGuard] Fixed regression in about:blank handling (thanks NDevTK for reporting). --- src/bg/TabGuard.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bg/TabGuard.js b/src/bg/TabGuard.js index 6480b87..834aa17 100644 --- a/src/bg/TabGuard.js +++ b/src/bg/TabGuard.js @@ -116,15 +116,28 @@ var TabGuard = (() => { tab._externalUrl = tab.url; tab._isExplicitOrigin = true; try { - tab.url = await browser.tabs.executeScript(tab.id, { + tab.url = await browser.tabs.executeScript(tab.id, { runAt: "document_start", code: "window.origin === 'null' ? window.location.href : window.origin" }); } catch (e) { + // We don't have permissions to run in this tab, probably because it has been left empty. debug(e); } - debug(`Real origin for ${tab._externalUrl} (tab ${tab.id}) is ${tab.url}.`); - if (!ns.policy.can(tab.url, "script")) return; + // If it's about:blank and it has got an opener, let's assume the opener + // 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)); }));