Verified Commit 9621ce2b authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

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.
parent 02844505
Loading
Loading
Loading
Loading
+28 −12
Original line number Diff line number Diff line
@@ -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;
    }
  },
+14 −0
Original line number Diff line number Diff line
@@ -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) {