Pier Angelo Vendrame pushed to branch tor-browser-128.6.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits: 266cf821 by Henry Wilkes at 2025-01-21T17:10:38+00:00 fixup! TB 40597: Implement TorSettings module
TB 41921: Reset bootstrap stage when bridge settings change.
In particular, this will cancel an autobootstrap when the user manually changes the bridge settings. However we apply this to all bootstrap attempts for consistency.
By resetting to the Start stage, we also ensure that about:torconnect UI no longer shows the "Try bridges" pages when the user manually changes their bridges themselves.
- - - - - ecdccd3f by Henry Wilkes at 2025-01-21T17:10:38+00:00 fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection
TB 41921: Also show the "Connect" button for bridge dialogs when we have an ongoing bootstrap attempt.
With the new behaviour, changing the settings while not bootstrapped will cancel any ongoing bootstrap. Therefore, we can start a new bootstrap using the new settings.
- - - - -
6 changed files:
- browser/components/torpreferences/content/builtinBridgeDialog.js - browser/components/torpreferences/content/connectionPane.js - browser/components/torpreferences/content/provideBridgeDialog.js - browser/components/torpreferences/content/requestBridgeDialog.js - toolkit/modules/TorConnect.sys.mjs - toolkit/modules/TorSettings.sys.mjs
Changes:
===================================== browser/components/torpreferences/content/builtinBridgeDialog.js ===================================== @@ -4,9 +4,8 @@ const { TorSettings, TorBridgeSource } = ChromeUtils.importESModule( "resource://gre/modules/TorSettings.sys.mjs" );
-const { TorConnect, TorConnectTopics } = ChromeUtils.importESModule( - "resource://gre/modules/TorConnect.sys.mjs" -); +const { TorConnect, TorConnectStage, TorConnectTopics } = + ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs");
const gBuiltinBridgeDialog = { init() { @@ -96,7 +95,7 @@ const gBuiltinBridgeDialog = { },
onAcceptStateChange() { - const connect = TorConnect.canBeginBootstrap; + const connect = TorConnect.stageName !== TorConnectStage.Bootstrapped; this._result.connect = connect; this._acceptButton.setAttribute( "data-l10n-id",
===================================== browser/components/torpreferences/content/connectionPane.js ===================================== @@ -2257,6 +2257,8 @@ const gBridgeSettings = { }
// Wait until the settings are applied before bootstrapping. + // NOTE: Saving the settings should also cancel any existing bootstrap + // attempt first. See tor-browser#41921. savedSettings.then(() => { // The bridge dialog button is "connect" when Tor is not // bootstrapped, so do the connect.
===================================== browser/components/torpreferences/content/provideBridgeDialog.js ===================================== @@ -3,9 +3,8 @@ const { TorSettings, TorBridgeSource, validateBridgeLines } = ChromeUtils.importESModule("resource://gre/modules/TorSettings.sys.mjs");
-const { TorConnect, TorConnectTopics } = ChromeUtils.importESModule( - "resource://gre/modules/TorConnect.sys.mjs" -); +const { TorConnect, TorConnectStage, TorConnectTopics } = + ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs");
const { TorParsers } = ChromeUtils.importESModule( "resource://gre/modules/TorParsers.sys.mjs" @@ -190,7 +189,7 @@ const gProvideBridgeDialog = { "user-provide-bridge-dialog-next-button" ); } else { - connect = TorConnect.canBeginBootstrap; + connect = TorConnect.stageName !== TorConnectStage.Bootstrapped; this._acceptButton.setAttribute( "data-l10n-id", connect ? "bridge-dialog-button-connect" : "bridge-dialog-button-accept"
===================================== browser/components/torpreferences/content/requestBridgeDialog.js ===================================== @@ -4,9 +4,8 @@ const { BridgeDB } = ChromeUtils.importESModule( "resource://gre/modules/BridgeDB.sys.mjs" );
-const { TorConnect, TorConnectTopics } = ChromeUtils.importESModule( - "resource://gre/modules/TorConnect.sys.mjs" -); +const { TorConnect, TorConnectStage, TorConnectTopics } = + ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs");
const log = console.createInstance({ maxLogLevel: "Warn", @@ -102,7 +101,7 @@ const gRequestBridgeDialog = { },
onAcceptStateChange() { - const connect = TorConnect.canBeginBootstrap; + const connect = TorConnect.stageName !== TorConnectStage.Bootstrapped; this._result.connect = connect; this._submitButton.setAttribute( "data-l10n-id",
===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -13,6 +13,7 @@ ChromeUtils.defineESModuleGetters(lazy, { TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs", TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs", TorSettings: "resource://gre/modules/TorSettings.sys.mjs", + TorSettingsTopics: "resource://gre/modules/TorSettings.sys.mjs", });
const TorConnectPrefs = Object.freeze({ @@ -629,16 +630,6 @@ class AutoBootstrapAttempt {
// Send the new settings directly to the provider. We will save them only // if the bootstrap succeeds. - // FIXME: We should somehow signal TorSettings users that we have set - // custom settings, and they should not apply theirs until we are done - // with trying ours. - // Otherwise, the new settings provided by the user while we were - // bootstrapping could be the ones that cause the bootstrap to succeed, - // but we overwrite them (unless we backup the original settings, and then - // save our new settings only if they have not changed). - // Another idea (maybe easier to implement) is to disable the settings - // UI while *any* bootstrap is going on. - // This is also documented in tor-browser#41921. await lazy.TorSettings.applyTemporaryBridges(bridges);
if (this.#cancelled || this.#resolved) { @@ -1036,6 +1027,7 @@ export const TorConnect = { // register the Tor topics we always care about observeTopic(lazy.TorProviderTopics.ProcessExited); observeTopic(lazy.TorProviderTopics.HasWarnOrErr); + observeTopic(lazy.TorSettingsTopics.SettingsChanged);
// NOTE: At this point, _requestedStage should still be `null`. this._setStage(TorConnectStage.Start); @@ -1070,8 +1062,32 @@ export const TorConnect = { Services.prefs.setBoolPref(TorConnectPrefs.prompt_at_startup, true); this._makeStageRequest(TorConnectStage.Start, true); break; - default: - // ignore + case lazy.TorSettingsTopics.SettingsChanged: + if ( + this._stageName !== TorConnectStage.Bootstrapped && + this._stageName !== TorConnectStage.Loading && + this._stageName !== TorConnectStage.Start && + subject.wrappedJSObject.changes.some(propertyName => + propertyName.startsWith("bridges.") + ) + ) { + // A change in bridge settings before we are bootstrapped, we reset + // the stage to Start to: + // + Cancel any ongoing bootstrap attempt. In particular, we + // definitely do not want to continue with an auto-bootstrap's + // temporary bridges if the settings have changed. + // + Reset the UI to be ready for normal bootstrapping in case the + // user returns to about:torconnect. + // See tor-browser#41921. + // NOTE: We do not reset in response to a change in the quickstart, + // firewall or proxy settings. + lazy.logger.warn( + "Resetting to Start stage since bridge settings changed" + ); + // Rather than cancel and return to the pre-bootstrap stage, we + // explicitly cancel and return to the start stage. + this._makeStageRequest(TorConnectStage.Start); + } break; } },
===================================== toolkit/modules/TorSettings.sys.mjs ===================================== @@ -953,6 +953,7 @@ class TorSettingsImpl { };
if ("bridges" in newValues) { + const changesLength = changes.length; if ("source" in newValues.bridges) { this.#fixupBridgeSettings(newValues.bridges); changeSetting("bridges", "source", newValues.bridges.source); @@ -982,6 +983,19 @@ class TorSettingsImpl { if ("enabled" in newValues.bridges) { changeSetting("bridges", "enabled", newValues.bridges.enabled); } + + if (this.#temporaryBridgeSettings && changes.length !== changesLength) { + // A change in the bridges settings. + // We want to clear the temporary bridge settings to ensure that they + // cannot be used to overwrite these user-provided settings. + // See tor-browser#41921. + // NOTE: This should also trigger TorConnect to cancel any ongoing + // AutoBootstrap that would have otherwise used these settings. + this.#temporaryBridgeSettings = null; + lazy.logger.warn( + "Cleared temporary bridges since bridge settings were changed" + ); + } }
if ("proxy" in newValues) {
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/0bb78ca...
tor-commits@lists.torproject.org