Pier Angelo Vendrame pushed to branch tor-browser-155.0a1-17.0-1 at The Tor Project / Applications / Tor Browser Commits: 2ee1e06a by Elena at 2026-11-05T22:52:43+01:00 fixup! TB 40933: Add tor-launcher functionality TB 45425: Use an actual XPCOM type for status updates. - - - - - ab560c67 by Elena at 2026-11-05T22:52:43+01:00 fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection TB 45425: Use an actual XPCOM type for status updates. - - - - - 89e4cd8d by Elena at 2026-11-05T22:52:43+01:00 fixup! TB 42247: Android helpers for the TorProvider TB 45425: Use an actual XPCOM type for status updates. - - - - - 46369c80 by Elena at 2026-11-05T22:52:43+01:00 fixup! TB 3455: Add DomainIsolator, for isolating circuit by domain. TB 45425: Use an actual XPCOM type for provider topics. - - - - - 93647f33 by Pier Angelo Vendrame at 2026-11-05T22:52:44+01:00 fixup! TB 41600: Add a tor circuit display panel. TB 45425: Use an explicit boolean for bridges in NodeData - - - - - 11 changed files: - browser/components/torcircuit/content/torCircuitPanel.js - browser/components/torpreferences/content/torLogDialog.js - toolkit/components/tor-launcher/TorBootstrapRequest.sys.mjs - toolkit/components/tor-launcher/TorDomainIsolator.sys.mjs - toolkit/components/tor-launcher/TorLauncherUtil.sys.mjs - toolkit/components/tor-launcher/TorProvider.sys.mjs - toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs - toolkit/components/tor-launcher/TorProviderMock.sys.mjs - toolkit/components/tor-launcher/moz.build - + toolkit/components/tor-launcher/tor-launcher.idl - toolkit/modules/TorAndroidIntegration.sys.mjs Changes: ===================================== browser/components/torcircuit/content/torCircuitPanel.js ===================================== @@ -547,9 +547,9 @@ var gTorCircuitPanel = { // bridge, or otherwise a guard. document.l10n.setAttributes( this._panelElements.newCircuitDescription, - nodes[0].bridgeType === null - ? "tor-circuit-panel-new-button-description-guard" - : "tor-circuit-panel-new-button-description-bridge" + nodes[0].isBridge + ? "tor-circuit-panel-new-button-description-bridge" + : "tor-circuit-panel-new-button-description-guard" ); }, @@ -565,7 +565,7 @@ var gTorCircuitPanel = { const nameEl = nodeItem.querySelector(".tor-circuit-node-name"); let flagSrc = null; - if (node.bridgeType === null) { + if (!node.isBridge) { const regionCode = node.regionCode; flagSrc = this._regionFlagSrc(regionCode); ===================================== browser/components/torpreferences/content/torLogDialog.js ===================================== @@ -87,7 +87,13 @@ const gTorLogDialog = { observe(subject, topic) { if (topic === TorProviderTopics.TorLog) { - this.addLogEntry(subject.wrappedJSObject, false); + let entry; + try { + entry = subject.QueryInterface(Ci.torITorLogEntry); + } catch { + return; + } + this.addLogEntry(entry, false); } }, @@ -96,7 +102,7 @@ const gTorLogDialog = { timeEl.textContent = logEntry.timestamp; timeEl.classList.add("time"); const messageEl = document.createElement("td"); - messageEl.textContent = `[${logEntry.type}] ${logEntry.msg}`; + messageEl.textContent = `[${logEntry.severity}] ${logEntry.message}`; messageEl.classList.add("message"); const row = document.createElement("tr"); ===================================== toolkit/components/tor-launcher/TorBootstrapRequest.sys.mjs ===================================== @@ -7,6 +7,8 @@ ChromeUtils.defineESModuleGetters(lazy, { "moz-src:///toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs", TorProviderTopics: "moz-src:///toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs", + TorBootstrapError: + "moz-src:///toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs", }); const log = console.createInstance({ @@ -35,12 +37,18 @@ export class TorBootstrapRequest { #timeoutID = null; observe(subject, topic) { - const obj = subject?.wrappedJSObject; switch (topic) { case lazy.TorProviderTopics.BootstrapStatus: { - const progress = obj.PROGRESS; + let obj; + try { + obj = subject.QueryInterface(Ci.torITorBootstrapStatus); + } catch (e) { + log.warn("BootstrapStatus with an unexpected subject", e, subject); + break; + } + const progress = obj.progress; if (this.onbootstrapstatus) { - const status = obj.TAG; + const status = obj.tag; this.onbootstrapstatus(progress, status); } if (progress === 100) { @@ -55,8 +63,21 @@ export class TorBootstrapRequest { break; } case lazy.TorProviderTopics.BootstrapError: { + let obj; + try { + obj = subject.QueryInterface(Ci.torITorBootstrapStatus); + } catch (e) { + log.warn("TorBootstrapError with an unexpected subject", e, subject); + break; + } log.info("TorBootstrapRequest: observerd TorBootstrapError", obj); - this.#stop(obj); + this.#stop( + new lazy.TorBootstrapError({ + phase: obj.tag, + summary: obj.summary, + reason: obj.reason, + }) + ); break; } } ===================================== toolkit/components/tor-launcher/TorDomainIsolator.sys.mjs ===================================== @@ -288,8 +288,34 @@ class TorDomainIsolatorImpl { // TODO: What UX to use here? See tor-browser#41708 } } else if (topic === lazy.TorProviderTopics.CircuitCredentialsMatched) { - const { username, password, circuits } = subject.wrappedJSObject; - this.#updateCircuits(username, password, circuits); + let streamInfo; + try { + streamInfo = subject?.QueryInterface(Ci.torITorStreamInfo); + } catch (e) { + logger.warn( + "CircuitCredentialsMatched with invalid stream info", + e, + subject + ); + } + if (streamInfo) { + const circuits = streamInfo.circuits?.map(circuit => + circuit.map(node => { + return { + fingerprint: node.fingerprint, + ipAddrs: node.ipAddrs, + isBridge: node.isBridge, + bridgeType: node.bridgeType, + regionCode: node.regionCode, + }; + }) + ); + this.#updateCircuits( + streamInfo.socksUsername, + streamInfo.socksPassword, + circuits + ); + } } } ===================================== toolkit/components/tor-launcher/TorLauncherUtil.sys.mjs ===================================== @@ -644,17 +644,22 @@ export const TorLauncherUtil = { * Therefore, the messages should avoid containing any information that might * identify information about the user. * - * @param {string} type The log type (ERR, WARN, etc...) - * @param {string} msg The log message + * @param {string} severity The log severity (ERR, WARN, etc...) + * @param {string} message The log message */ - log(type, msg) { + log(severity, message) { const timestamp = new Date().toISOString().replace("T", " ").replace("Z", "") + " UTC"; Services.obs.notifyObservers( - { type, msg, timestamp }, + { + severity, + message, + timestamp, + QueryInterface: ChromeUtils.generateQI([Ci.torITorLogEntry]), + }, lazy.TorProviderTopics.TorLog ); - if (type === "WARN" || type === "ERR") { + if (severity === "WARN" || severity === "ERR") { // Notify so that Copy Log can be enabled. Services.obs.notifyObservers(null, lazy.TorProviderTopics.HasWarnOrErr); } ===================================== toolkit/components/tor-launcher/TorProvider.sys.mjs ===================================== @@ -7,10 +7,7 @@ import { clearTimeout, setTimeout } from "resource://gre/modules/Timer.sys.mjs"; import { TorLauncherUtil } from "moz-src:///toolkit/components/tor-launcher/TorLauncherUtil.sys.mjs"; import { TorParsers } from "moz-src:///toolkit/components/tor-launcher/TorParsers.sys.mjs"; import { TorProviderBase } from "moz-src:///toolkit/components/tor-launcher/TorProviderBase.sys.mjs"; -import { - TorBootstrapError, - TorProviderTopics, -} from "moz-src:///toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs"; +import { TorProviderTopics } from "moz-src:///toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs"; const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { @@ -57,12 +54,12 @@ const logger = console.createInstance({ * @typedef NodeData * @property {NodeFingerprint} fingerprint The node fingerprint * @property {string[]} ipAddrs The ip addresses associated with this node - * @property {string?} bridgeType The bridge type for this node, or "" if the - * node is a bridge but the type is unknown, or null if this is not a bridge - * node - * @property {string?} regionCode An upper case 2-letter ISO3166-1 code for the - * first ip address, or null if there is no region. This should also be a - * valid BCP47 Region subtag + * @property {boolean} isBridge Whether the node is a bridge. + * @property {string} bridgeType The bridge type for this node, or an empty + * string if the type is unknown or the node is not a bridge. + * @property {string} regionCode An upper case 2-letter ISO3166-1 code for the + * first ip address. This should also be a valid BCP47 Region subtag. + * It will be an empty string if the node is not a bridge. */ const Preferences = Object.freeze({ @@ -929,14 +926,16 @@ export class TorProvider extends TorProviderBase { const node = { fingerprint: id, ipAddrs: [], - bridgeType: null, - regionCode: null, + isBridge: false, + bridgeType: "", + regionCode: "", }; const bridge = (await this.#controller.getBridges())?.find( foundBridge => foundBridge.id?.toUpperCase() === id.toUpperCase() ); if (bridge) { + node.isBridge = true; node.bridgeType = bridge.transport ?? ""; // Attempt to get an IP address from bridge address string. const ip = bridge.addr.match(/^\[?([^\]]+)\]?:\d+$/)?.[1]; @@ -1006,7 +1005,10 @@ export class TorProvider extends TorProviderBase { */ #processBootstrapStatus(statusObj, isNotification) { // Notify observers - Services.obs.notifyObservers(statusObj, TorProviderTopics.BootstrapStatus); + Services.obs.notifyObservers( + new TorBootstrapStatus(statusObj), + TorProviderTopics.BootstrapStatus + ); if (statusObj.PROGRESS === 100) { return; @@ -1044,11 +1046,7 @@ export class TorProvider extends TorProviderBase { // anymore, since the first error eligible for notification will as a // matter of fact cancel the bootstrap. Services.obs.notifyObservers( - new TorBootstrapError({ - phase: statusObj.TAG, - reason: statusObj.REASON, - summary: statusObj.SUMMARY, - }), + new TorBootstrapStatus(statusObj), TorProviderTopics.BootstrapError ); } @@ -1147,14 +1145,24 @@ export class TorProvider extends TorProviderBase { * @param {StreamID} _streamId The ID of the stream that switched to the * sentconnect status. * @param {CircuitID} circuitId The ID of the circuit used by the stream - * @param {string} username The SOCKS username - * @param {string} password The SOCKS password + * @param {string} socksUsername The SOCKS username + * @param {string} socksPassword The SOCKS password */ - async onStreamSentConnect(_streamId, circuitId, username, password) { - if (!username || !password) { + async onStreamSentConnect( + _streamId, + circuitId, + socksUsername, + socksPassword + ) { + if (!socksUsername || !socksPassword) { return; } - logger.debug("Stream sentconnect event", username, password, circuitId); + logger.debug( + "Stream sentconnect event", + socksUsername, + socksPassword, + circuitId + ); if (!this.#circuits.has(circuitId)) { // tor-browser#42132: When using onion-grater (e.g., in Tails), we might // not receive the CIRC BUILT event, as it is impossible to know whether @@ -1194,13 +1202,33 @@ export class TorProvider extends TorProviderBase { ); Services.obs.notifyObservers( { - wrappedJSObject: { - username, - password, - circuits, - }, + socksUsername, + socksPassword, + circuits, + QueryInterface: ChromeUtils.generateQI([Ci.torITorStreamInfo]), }, TorProviderTopics.CircuitCredentialsMatched ); } } + +/** + * A JavaScript implementation of torITorBootstrapStatus. + */ +class TorBootstrapStatus { + /** + * Construct a typed status object from a status object sent by TorController. + * + * @param {object} statusObj The status object parsed by the controller + */ + constructor(statusObj) { + this.progress = statusObj.PROGRESS; + this.severity = statusObj.TYPE; + this.tag = statusObj.TAG; + this.summary = statusObj.SUMMARY; + this.reason = statusObj.REASON ?? ""; + this.shouldWarn = statusObj.RECOMMENDATION !== "ignore"; + } + + QueryInterface = ChromeUtils.generateQI([Ci.torITorBootstrapStatus]); +} ===================================== toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs ===================================== @@ -81,9 +81,9 @@ export const TorProviders = Object.freeze({ /** * @typedef {object} LogEntry An object with a log message - * @property {string} timestamp The local date-time stamp at which we received the message - * @property {string} type The message level - * @property {string} msg The message + * @property {string} timestamp The UTC date-time stamp at which we received the message + * @property {string} severity The message severity + * @property {string} message The message */ /** @@ -182,7 +182,18 @@ export class TorProviderBuilder { 1000 ); this.#logObserver = subject => { - this.#addLogEntry(subject.wrappedJSObject); + let entry; + try { + entry = subject.QueryInterface(Ci.torITorLogEntry); + } catch (e) { + lazy.logger.warn("TorLog with invalid subject", e, subject); + return; + } + this.#addLogEntry({ + severity: entry.severity, + message: entry.message, + timestamp: entry.timestamp, + }); }; Services.obs.addObserver(this.#logObserver, TorProviderTopics.TorLog); ===================================== toolkit/components/tor-launcher/TorProviderMock.sys.mjs ===================================== @@ -3,19 +3,19 @@ import { TorProviderBase } from "moz-src:///toolkit/components/tor-launcher/TorP import { TorProviderTopics } from "moz-src:///toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs"; const kBootstrapSteps = [ - { PROGRESS: 5, TAG: "starting", SUMMARY: "Starting" }, - { PROGRESS: 14, TAG: "handshake", SUMMARY: "Handshaking with a relay" }, + { progress: 5, tag: "starting", summary: "Starting" }, + { progress: 14, tag: "handshake", summary: "Handshaking with a relay" }, { - PROGRESS: 45, - TAG: "requesting_descriptors", - SUMMARY: "Asking for relay descriptors", + progress: 45, + tag: "requesting_descriptors", + summary: "Asking for relay descriptors", }, { - PROGRESS: 75, - TAG: "loading_descriptors", - SUMMARY: "Loading relay descriptors", + progress: 75, + tag: "loading_descriptors", + summary: "Loading relay descriptors", }, - { PROGRESS: 100, TAG: "done", SUMMARY: "Done" }, + { progress: 100, tag: "done", summary: "Done" }, ]; const kBootstrapStepDelayMs = 500; @@ -48,7 +48,15 @@ export class TorProviderMock extends TorProviderBase { const id = setTimeout( () => { Services.obs.notifyObservers( - { ...step, TYPE: "NOTICE" }, + { + ...step, + severity: "NOTICE", + reason: "", + shouldWarn: false, + QueryInterface: ChromeUtils.generateQI([ + Ci.torITorBootstrapStatus, + ]), + }, TorProviderTopics.BootstrapStatus ); }, ===================================== toolkit/components/tor-launcher/moz.build ===================================== @@ -1,3 +1,6 @@ +XPIDL_MODULE = "torlauncher" +XPIDL_SOURCES += ["tor-launcher.idl"] + MOZ_SRC_FILES += [ "TorBootstrapRequest.sys.mjs", "TorControlPort.sys.mjs", ===================================== toolkit/components/tor-launcher/tor-launcher.idl ===================================== @@ -0,0 +1,55 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +/** + * The information about the bootstrap status. + * The values are extracted from C-tor's STATUS_CLIENT events, except for + * shouldWarn, which is derived from the RECOMMENDATION value. + */ +[scriptable, uuid(64b3197d-0b1e-46a1-aa18-8cea11bacf97)] +interface torITorBootstrapStatus : nsISupports { + readonly attribute octet progress; + readonly attribute ACString severity; + readonly attribute ACString tag; + readonly attribute ACString summary; + readonly attribute ACString reason; + readonly attribute boolean shouldWarn; +}; + +/** + * A tor log message. + * The severity might be also something not used by C-tor. + */ +[scriptable, uuid(f6d18f7d-c29c-4bf3-bf70-7d6bed3b427e)] +interface torITorLogEntry : nsISupports { + readonly attribute ACString severity; + readonly attribute ACString message; + readonly attribute ACString timestamp; +}; + +/** + * A tor node information. + * The bridgeType and regionCode should be used only when isBridge is true. + */ +[scriptable, uuid(7547d8e5-a93e-4a0c-9876-a7a2cc44e80f)] +interface torITorNodeInfo : nsISupports { + readonly attribute ACString fingerprint; + readonly attribute Array<ACString> ipAddrs; + readonly attribute boolean isBridge; + readonly attribute ACString bridgeType; + readonly attribute ACString regionCode; +}; + +/** + * The information to associate a SOCKS isolation credential (the combination + * of SOCKS username and password) to one or more circuits. + */ +[scriptable, uuid(a85269dc-1aca-4aec-87a6-88ff035f0eaa)] +interface torITorStreamInfo : nsISupports { + readonly attribute ACString socksUsername; + readonly attribute ACString socksPassword; + readonly attribute Array<Array<torITorNodeInfo> > circuits; +}; ===================================== toolkit/modules/TorAndroidIntegration.sys.mjs ===================================== @@ -130,13 +130,19 @@ class TorAndroidIntegrationImpl { {} ); break; - case lazy.TorProviderTopics.TorLog: - lazy.EventDispatcher.instance.sendRequest(EmittedEvents.torLogs, { - logType: subj.wrappedJSObject.type ?? "", - message: subj.wrappedJSObject.msg ?? "", - timestamp: subj.wrappedJSObject.timestamp ?? "", - }); + case lazy.TorProviderTopics.TorLog: { + try { + const entry = subj.QueryInterface(Ci.torITorLogEntry); + lazy.EventDispatcher.instance.sendRequest(EmittedEvents.torLogs, { + logType: entry.severity, + message: entry.message, + timestamp: entry.timestamp, + }); + } catch (e) { + logger.warn("Failed to dispatch a log event", e, subj); + } break; + } case lazy.TorSettingsTopics.Ready: lazy.EventDispatcher.instance.sendRequest(EmittedEvents.settingsReady, { settings: lazy.TorSettings.getSettings(), View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/9f3470c... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/9f3470c... You're receiving this email because of your account on gitlab.torproject.org. Manage all notifications: https://gitlab.torproject.org/-/profile/notifications | Help: https://gitlab.torproject.org/help