Skip to content

Commit 1ccbcc5

Browse files
committed
[tor-browser#32668] Use the Security Level as the default policy for Options Reset on Tor Browser.
1 parent 5e3e15f commit 1ccbcc5

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/bg/Settings.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var Settings = {
102102
ns.defaults.local.isTorBrowser = true; // prevents reset from forgetting
103103
ns.defaults.sync.cascadeRestrictions = true; // we want this to be the default even on reset
104104
Sites.onionSecure = true;
105-
105+
ns.local.torBrowserPolicy = policy; // save for reset
106106
if (!this.gotTorBrowserInit) {
107107
// First initialization message from the Tor Browser
108108
this.gotTorBrowserInit = true;
@@ -111,13 +111,14 @@ var Settings = {
111111
// copying the Security Level preset on startup (only).
112112
// Manually changing the security level works as usual.
113113
ns.local.isTorBrowser = true;
114-
await ns.save(ns.local);
114+
await Promise.all([ns.saveSession(), ns.save(ns.local)]);
115+
this.reloadOptionsUI();
115116
return;
116117
}
117-
} else {
118-
reloadOptionsUI = true;
119118
}
120119

120+
reloadOptionsUI = true;
121+
121122
if (policy && policy.TRUSTED) {
122123
// Gracefully handle "new" capabilities still unknown to our settings host
123124
const knownCapabilities = settingsHost && settingsHost.knownCapabilities
@@ -151,13 +152,9 @@ var Settings = {
151152
}
152153

153154
if (settings.sync === null) {
154-
// user is resetting options
155-
policy = this.createDefaultDryPolicy();
156-
157-
// overriden defaults when user manually resets options
158-
159-
// we want the reset options to stick (otherwise it gets very confusing)
160-
ns.defaults.sync.overrideTorBrowserPolicy = true;
155+
// User is resetting options:
156+
// pick either current Tor Browser Security Level or default NoScript policy
157+
policy = ns.local.torBrowserPolicy || this.createDefaultDryPolicy();
161158
reloadOptionsUI = true;
162159
}
163160

src/bg/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,12 @@
7171
if (data) {
7272
ns.policy = new Policy(data.policy);
7373
ns.unrestrictedTabs = new Set(data.unrestrictedTabs);
74-
Settings.gotTorBrowserInit = data.gotTorBrowserInit;
7574
}
7675
},
7776
beforeSave() { // beforeSave
7877
return {
7978
policy: ns.policy.dry(true),
8079
unrestrictedTabs: [...ns.unrestrictedTabs],
81-
gotTorBrowserInit: Settings.gotTorBrowserInit,
8280
};
8381
},
8482
}
@@ -401,6 +399,10 @@
401399
return obj;
402400
},
403401

402+
async saveSession() {
403+
await session.save();
404+
},
405+
404406
async collectSeen(tabId) {
405407
await this.initializing;
406408
try {

0 commit comments

Comments
 (0)