You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tor: AUTHENTICATE quotes the password without escaping it #1100
Found by the round-9 static review of #870 (PR #1094). Pre-existing on rewrite/main at 68be6f3: the file is untouched by that PR.
The mechanism
crates/nostream-services/src/tor.rs:146-148:
let reply = client
.send_command(&format!("AUTHENTICATE \"{password}\"")).await?;
The Tor control protocol is quoted-string based, with \ and the quote escaped by backslash. A password containing either is sent as different text — or truncates the command — so 250 never arrives, TorClient::connect returns an auth error, and the hidden service stays disabled while TOR_PASSWORD is correct in the settings.
This fails closed (no service rather than a wrong one), which is why it has not been noticed: the symptom is "Tor does not start", and the first suspect is the torrc rather than the quoting.
What a fix needs
Escape \ and " in the quoted value, or send the password as hex (AUTHENTICATE <hex>, which the protocol also accepts and which removes the quoting question entirely). A test can assert the exact command line for a password containing " and \ against a control-port double.
In TorClient::connect, escape the password prior to formatting the AUTHENTICATE "{escaped}" command, ensuring passwords with special characters/quotes authenticate properly without truncation.
Testing:
Add unit tests for escape_tor_quoted_string covering empty passwords, quotes, backslashes, and combined edge cases.
Add a test against a local mock TcpListener control port to verify that TorClient::connect transmits the exact wire-format command string (e.g. AUTHENTICATE "pass\"word\\test"\r\n) and handles 250 OK.
The changes will be kept strictly focused on tor.rs with no unrelated edits. Looking forward to your approval to proceed!
Added escape_tor_quoted_string to escape backslashes (\) and double quotes (") per the Tor control protocol specification.
Updated TorClient::connect to escape the password before formatting AUTHENTICATE "{escaped}".
Added unit tests covering escape_tor_quoted_string edge cases (quotes, backslashes, empty, mixed) and an end-to-end TorClient::connect test against a mock TcpListener asserting the wire-format AUTHENTICATE "pass\"word\\test"\r\n command and 250 OK handling.
Implemented in #1129, and @tirthraj01's analysis is credited there.
The escaping function is the same shape as the branch's. Two things stopped the branch landing as-is: it is 51 commits behind rewrite/main, and both new tests were pasted inside a_write_into_a_missing_directory_fails — they compiled as nested items, never registered, and the suite still ran only the four pre-existing tests. #1129 carries the same check as a module-level test that asserts the exact wire bytes, plus CR and LF escaping so a password containing a newline cannot start a second command.
That makes total sense regarding the test nesting and CRLF injection guard. Really appreciate you taking the time to explain it looking forward to contributing more to the repository!
@cameri yes, #1061! Saw the Node 24.22.2 bump is fully spelled out and nobody's on it yet, so I'd love to grab it. I'll move .nvmrc + all 7 image pins to the new digest in one commit, check the pin test, both Docker builds and the migrate container, and target rewrite/main first. Can have it up soon!
Activity
AgrimTawani commentedon Nov 11, 2026
Hi @chappie-daemon! Could I be assigned to this?
I have understood the issue, and here is my approach:
AUTHENTICATE <hex(password)>inTorClient::connect, which removes quoting entirelyAUTHENTICATEinstead of an empty hex argtor.rsusing aTcpListenercontrol-port double: password with"and\, assert the exact command line, reply250 OKtirthraj01 commentedon Nov 12, 2026
Hi @cameri @chappie-daemon,
I would like to work on this issue! Please assign it to me.
Proposed Approach:
crates/nostream-services/src/tor.rsonrewrite/main.\) and double quotes (") per the Tor control protocol specification:TorClient::connect, escape the password prior to formatting theAUTHENTICATE "{escaped}"command, ensuring passwords with special characters/quotes authenticate properly without truncation.escape_tor_quoted_stringcovering empty passwords, quotes, backslashes, and combined edge cases.TcpListenercontrol port to verify thatTorClient::connecttransmits the exact wire-format command string (e.g.AUTHENTICATE "pass\"word\\test"\r\n) and handles250 OK.The changes will be kept strictly focused on
tor.rswith no unrelated edits. Looking forward to your approval to proceed!cameri commentedon Nov 12, 2026
@tirthraj01 Assigned!
@AgrimTawani is there another ticket that interests you?
tirthraj01 commentedon Nov 13, 2026
Hi @cameri @chappie-daemon,
I have completed the fix for #1100:
Summary of Changes:
escape_tor_quoted_stringto escape backslashes (\) and double quotes (") per the Tor control protocol specification.TorClient::connectto escape the password before formattingAUTHENTICATE "{escaped}".escape_tor_quoted_stringedge cases (quotes, backslashes, empty, mixed) and an end-to-endTorClient::connecttest against a mockTcpListenerasserting the wire-formatAUTHENTICATE "pass\"word\\test"\r\ncommand and250 OKhandling..changeset/tor-authenticate-escaping.md.Branch compare link:
rewrite/main...tirthraj01:nostream:fix/1100-tor-authenticate-escaping
Because repository interaction limits are active, please feel free to open the PR or cherry-pick from this branch!
chappie-daemon commentedon Nov 14, 2026
Implemented in #1129, and @tirthraj01's analysis is credited there.
The escaping function is the same shape as the branch's. Two things stopped the branch landing as-is: it is 51 commits behind
rewrite/main, and both new tests were pasted insidea_write_into_a_missing_directory_fails— they compiled as nested items, never registered, and the suite still ran only the four pre-existing tests. #1129 carries the same check as a module-level test that asserts the exact wire bytes, plus CR and LF escaping so a password containing a newline cannot start a second command.tirthraj01 commentedon Nov 14, 2026
Thank you @cameri @chappie-daemon for the credit in #1129 and for the detailed feedback!
That makes total sense regarding the test nesting and CRLF injection guard. Really appreciate you taking the time to explain it looking forward to contributing more to the repository!
fix(tor): escape the control-port password before it is quoted
AgrimTawani commentedon Nov 15, 2026
@cameri yes, #1061! Saw the Node 24.22.2 bump is fully spelled out and nobody's on it yet, so I'd love to grab it. I'll move
.nvmrc+ all 7 image pins to the new digest in one commit, check the pin test, both Docker builds and the migrate container, and targetrewrite/mainfirst. Can have it up soon!