From 06b9b455bc0a7272762fdde08a798aebd8b020b8 Mon Sep 17 00:00:00 2001 From: hackademix Date: Sat, 24 Aug 2024 11:27:50 +0200 Subject: [PATCH] Gracefully handle new capabilities still unknown to the settings host (e.g. Tor/Mullvad browser), if any. --- src/bg/Settings.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/bg/Settings.js b/src/bg/Settings.js index 0312606..01cb3d2 100644 --- a/src/bg/Settings.js +++ b/src/bg/Settings.js @@ -103,6 +103,7 @@ var Settings = { unrestrictedTab, reloadAffected, isTorBrowser, + settingsHost, } = settings; debug("Received settings ", settings); let oldDebug = ns.local.debug; @@ -130,6 +131,25 @@ var Settings = { reloadOptionsUI = true; } + if (policy && policy.TRUSTED) { + // Gracefully handle "new" capabilities still unknown to our settings host + const knownCapabilities = settingsHost && settingsHost.knownCapabilities + || policy.TRUSTED.capabilities; + + for (const cap of ["lazy_load", "unchecked_css"]) { + // Scripting far exceeds the security/privacy concerns around these capabilities, + // so enable them on script-capable presets unless our settingsHost knows better. + if (cap in knownCapabilities) continue; + for (const preset of ["TRUSTED", "UNTRUSTED", "DEFAULT"]) { + if (!policy[preset]) continue; + const {capabilities} = policy[preset]; + if (capabilities.includes("script") && !capabilities.includes(cap)) { + capabilities.push(cap); + } + } + } + } + let torBrowserSettings = { local: { isTorBrowser: true,