Skip to content

Commit f7d56c3

Browse files
committed
Configurable "csspp0" capability to for sites where the CSS PP0 mitigation should be disabled (e.g TRUSTED).
1 parent fee3a23 commit f7d56c3

3 files changed

Lines changed: 38 additions & 27 deletions

File tree

src/bg/LifeCycle.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,24 +240,34 @@ var LifeCycle = (() => {
240240

241241
// put here any version specific upgrade adjustment in stored data
242242

243-
if (Ver.is(previousVersion, "<=", "11.0.10")) {
244-
log(`Upgrading from 11.0.10 or below (${previousVersion}): configure the "ping" capability.`);
245-
await ns.initializing;
246-
ns.policy.TRUSTED.capabilities.add("ping");
247-
await ns.savePolicy();
248-
}
249-
if (Ver.is(previousVersion, "<=", "11.2.1")) {
250-
log(`Upgrading from ${previousVersion}: configure the "noscript" capability.`);
243+
let configureNewCap = async(cap, presets, presetFilter) => {
244+
log(`Upgrading from ${previousVersion}: configure the "${cap}" capability.`);
251245
await ns.initializing;
252-
let {DEFAULT, TRUSTED, UNTRUSTED} = ns.policy;
253-
// let's add "noscript" to DEFAULY, TRUSTED and any CUSTOM preset
254-
let presets = [DEFAULT, TRUSTED];
255-
presets = presets.concat([...ns.policy.sites.values()].filter(p => p !== TRUSTED && p !== UNTRUSTED));
246+
let policy = ns.policy;
247+
let customIdx = presets.indexOf("CUSTOM");
248+
presets = presets.map(p => policy[p])
249+
if (customIdx !== -1) {
250+
let { TRUSTED, UNTRUSTED } = policy;
251+
// insert custom presets, if any
252+
presets.splice(customIdx, 1, ...[...policy.sites.values()].filter(p => p !== TRUSTED && p !== UNTRUSTED));
253+
}
254+
if (presetFilter) presets = presets.filter(presetFilter);
256255
for (let p of presets) {
257-
p.capabilities.add("noscript");
256+
p.capabilities.add(cap);
258257
}
259258
await ns.savePolicy();
260259
}
260+
261+
if (Ver.is(previousVersion, "<=", "11.0.10")) {
262+
await configureNewCap("ping", ["TRUSTED"]);
263+
}
264+
if (Ver.is(previousVersion, "<=", "11.2.1")) {
265+
await configureNewCap("noscript", ["DEFAULT", "TRUSTED", "CUSTOM"])
266+
}
267+
if (Ver.is(previousVersion, "<=", "11.2.4")) {
268+
// add the csspp0 capability to any preset which already has the script capability
269+
await configureNewCap("csspp0", ["TRUSTED", "CUSTOM", "DEFAULT"], p => p.capabilities.has("script"));
270+
}
261271
},
262272

263273
async onUpdateAvailable(details) {

src/content/content.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ ns.on("capabilities", () => {
163163
allowed: ns.canScript
164164
});
165165

166+
if (!(ns.policy.isTorBrowser || ns.allows("csspp0"))) {
167+
// protection against CSS PP0, not needed on the Tor Browser because of its
168+
// noisy DNS resolution: https://orenlab.sise.bgu.ac.il/p/PP0
169+
let prefetchCallback =
170+
// false && // REL_ONLY
171+
(location.hostname === 'localhost' && location.search.includes("debug_prefetch"))
172+
? (rule, url) => {
173+
debug("Prefetching %s from CSS", url, rule.cssText);
174+
url.hostname = `prefetch.${url.hostname}`;
175+
return false; // let default processing continue with the modified hostname
176+
} : null;
177+
prefetchCSSResources(true, prefetchCallback);
178+
}
179+
166180
if (!ns.canScript) {
167181

168182
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
@@ -172,19 +186,6 @@ ns.on("capabilities", () => {
172186
}
173187
})();
174188
}
175-
if (!ns.policy.isTorBrowser) {
176-
// protection against CSS PP0, not needed on the Tor Browser because of its
177-
// noisy DNS resolution: https://orenlab.sise.bgu.ac.il/p/PP0
178-
let prefetchCallback =
179-
// false && // REL_ONLY
180-
(location.hostname === 'localhost' && location.search.includes("debug_prefetch"))
181-
? (rule, url) => {
182-
debug("Prefetching %s from CSS", url, rule.cssText);
183-
url.hostname = `prefetch.${url.hostname}`;
184-
return false; // let default processing continue with the modified hostname
185-
} : null;
186-
prefetchCSSResources(true, prefetchCallback);
187-
}
188189
onScriptDisabled();
189190
}
190191

src/nscl

0 commit comments

Comments
 (0)