[tor-browser#32668] Use the Security Level as the default policy for Options Reset on Tor Browser.

This commit is contained in:
hackademix 2024-10-25 23:52:28 +02:00
parent 5e3e15f9e6
commit 1ccbcc5da1
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
2 changed files with 12 additions and 13 deletions

View File

@ -102,7 +102,7 @@ var Settings = {
ns.defaults.local.isTorBrowser = true; // prevents reset from forgetting ns.defaults.local.isTorBrowser = true; // prevents reset from forgetting
ns.defaults.sync.cascadeRestrictions = true; // we want this to be the default even on reset ns.defaults.sync.cascadeRestrictions = true; // we want this to be the default even on reset
Sites.onionSecure = true; Sites.onionSecure = true;
ns.local.torBrowserPolicy = policy; // save for reset
if (!this.gotTorBrowserInit) { if (!this.gotTorBrowserInit) {
// First initialization message from the Tor Browser // First initialization message from the Tor Browser
this.gotTorBrowserInit = true; this.gotTorBrowserInit = true;
@ -111,13 +111,14 @@ var Settings = {
// copying the Security Level preset on startup (only). // copying the Security Level preset on startup (only).
// Manually changing the security level works as usual. // Manually changing the security level works as usual.
ns.local.isTorBrowser = true; ns.local.isTorBrowser = true;
await ns.save(ns.local); await Promise.all([ns.saveSession(), ns.save(ns.local)]);
this.reloadOptionsUI();
return; return;
} }
} else {
reloadOptionsUI = true;
} }
reloadOptionsUI = true;
if (policy && policy.TRUSTED) { if (policy && policy.TRUSTED) {
// Gracefully handle "new" capabilities still unknown to our settings host // Gracefully handle "new" capabilities still unknown to our settings host
const knownCapabilities = settingsHost && settingsHost.knownCapabilities const knownCapabilities = settingsHost && settingsHost.knownCapabilities
@ -151,13 +152,9 @@ var Settings = {
} }
if (settings.sync === null) { if (settings.sync === null) {
// user is resetting options // User is resetting options:
policy = this.createDefaultDryPolicy(); // pick either current Tor Browser Security Level or default NoScript policy
policy = ns.local.torBrowserPolicy || this.createDefaultDryPolicy();
// overriden defaults when user manually resets options
// we want the reset options to stick (otherwise it gets very confusing)
ns.defaults.sync.overrideTorBrowserPolicy = true;
reloadOptionsUI = true; reloadOptionsUI = true;
} }

View File

@ -71,14 +71,12 @@
if (data) { if (data) {
ns.policy = new Policy(data.policy); ns.policy = new Policy(data.policy);
ns.unrestrictedTabs = new Set(data.unrestrictedTabs); ns.unrestrictedTabs = new Set(data.unrestrictedTabs);
Settings.gotTorBrowserInit = data.gotTorBrowserInit;
} }
}, },
beforeSave() { // beforeSave beforeSave() { // beforeSave
return { return {
policy: ns.policy.dry(true), policy: ns.policy.dry(true),
unrestrictedTabs: [...ns.unrestrictedTabs], unrestrictedTabs: [...ns.unrestrictedTabs],
gotTorBrowserInit: Settings.gotTorBrowserInit,
}; };
}, },
} }
@ -401,6 +399,10 @@
return obj; return obj;
}, },
async saveSession() {
await session.save();
},
async collectSeen(tabId) { async collectSeen(tabId) {
await this.initializing; await this.initializing;
try { try {