Skip to content

Commit d97b2f6

Browse files
committed
Rename the "csspp0" capability to "unchecked_css".
1 parent 182cd5f commit d97b2f6

5 files changed

Lines changed: 39 additions & 19 deletions

File tree

src/_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@
551551
"cap_noscript": {
552552
"message": "noscript"
553553
},
554+
"cap_unchecked_css": {
555+
"message": "unchecked CSS"
556+
},
554557
"cap_other": {
555558
"message": "other"
556559
},

src/bg/LifeCycle.js

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

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

243-
let configureNewCap = async(cap, presets, presetFilter) => {
244-
log(`Upgrading from ${previousVersion}: configure the "${cap}" capability.`);
243+
let forEachPreset = async (callback, presetNames = "*") => {
245244
await ns.initializing;
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));
245+
let changed = false;
246+
for (let p of ns.policy.getPresets(presetNames)) {
247+
if (callback(p)) changed = true;
253248
}
254-
if (presetFilter) presets = presets.filter(presetFilter);
255-
for (let p of presets) {
256-
p.capabilities.add(cap);
249+
if (changed) {
250+
await ns.savePolicy();
257251
}
258-
await ns.savePolicy();
259-
}
252+
};
253+
254+
let configureNewCap = async (cap, presetNames, capsFilter) => {
255+
log(`Upgrading from ${previousVersion}: configure the "${cap}" capability.`);
256+
await forEachPreset(({capabilities}) => {
257+
if (capsFilter(capabilities) && !capabilities.has(cap)) {
258+
capabilities.add(cap);
259+
return true;
260+
}
261+
}, presetNames);
262+
};
263+
264+
let renameCap = async (oldName, newName) => {
265+
log(`Upgrading from ${previousVersion}: rename capability "${oldName}" to "${newName}`);
266+
await forEachPreset(({capabilities}) => {
267+
if (capabilities.has(oldName)) {
268+
capabilities.delete(oldName);
269+
capabilities.add(newName);
270+
return true;
271+
}
272+
});
273+
};
260274

261275
if (Ver.is(previousVersion, "<=", "11.0.10")) {
262276
await configureNewCap("ping", ["TRUSTED"]);
@@ -265,8 +279,11 @@ var LifeCycle = (() => {
265279
await configureNewCap("noscript", ["DEFAULT", "TRUSTED", "CUSTOM"])
266280
}
267281
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"));
282+
// add the unchecked_css capability to any preset which already has the script capability
283+
await configureNewCap("unchecked_css", ["DEFAULT", "TRUSTED", "CUSTOM"], caps => caps.has("script"));
284+
}
285+
if (Ver.is(previousVersion, "<=", "11.2.5rc1")) {
286+
await renameCap("csspp0", "unchecked_css");
270287
}
271288
},
272289

src/content/content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ns.on("capabilities", () => {
163163
allowed: ns.canScript
164164
});
165165

166-
if (!(ns.policy.isTorBrowser || ns.allows("csspp0"))) {
166+
if (!(ns.policy.isTorBrowser || ns.allows("unchecked_css"))) {
167167
// protection against CSS PP0, not needed on the Tor Browser because of its
168168
// noisy DNS resolution: https://orenlab.sise.bgu.ac.il/p/PP0
169169
let prefetchCallback =

src/nscl

Submodule nscl updated from 97c2a54 to efa5fbe

src/ui/ui.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ var UI = (() => {
362362
capInput.id = `capability-${capability}-${idSuffix}`
363363
capLabel.setAttribute("for", capInput.id);
364364
capInput.value = capability;
365-
capInput.title = capLabel.textContent = _(`cap_${capability}`) || capability;
365+
capInput.title = capLabel.textContent = _(`cap_${capability}`) || capability.replace(/_/g, ' ');
366366
let clone = capParent.appendChild(cap.cloneNode(true));
367367
clone.classList.add(capability);
368368
}

0 commit comments

Comments
 (0)