mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
torcontrol: escape backslashes in -torpassword #36374
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36374
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-torpassword-backslash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
With
HASHEDPASSWORDauthentication,TorController::protocolinfo_cbsends the password as a quoted string,AUTHENTICATE "<password>"(torcontrol.cpp:667). It escapes"but not\.Tor parses that argument as a control-spec QuotedString, where a backslash escapes the next character. So:
-torpassword=pa\ssreaches Tor aspass, authentication fails and no onion service is created-torpassword=pass\escapes the closing quote, so the command is malformedThis escapes backslashes before quotes.
The new
test_password_escapinginfeature_torcontrol.pyuses the mock control server withHASHEDPASSWORDand-torpassword=pa\ss"word\, and checks the exactAUTHENTICATEline. On master it getsAUTHENTICATE "pa\ss\"word\", with the fixAUTHENTICATE "pa\\ss\"word\\".Tested against Tor 0.4.9.12 with
HashedControlPasswordset forpa\ss"word\: on master bitcoind logs "tor: Authentication failed", with this change authentication succeeds and ADD_ONION creates the onion service.AI tools were used to help find this issue and to prepare the patch and test.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
🟠 Minor · Exercise the successful hashed-password flow in the mock
feature_torcontrol.py:115-124: HashedPasswordTorControlServer passes the quoted AUTHENTICATE to the base mock, which replies 510 (lines 102-112). auth_cb then logs a failure, so the new test never covers successful HASHEDPASSWORD authentication or the ADD_ONION that should follow.
Location:
test/functional/feature_torcontrol.py:102(head).🔵 Suggestion · Quoted authentication retains an avoidable escaping dependency
The new escaping is correct, but sending the password as hex would avoid the order-dependent replacements and keep password bytes out of the line-based command syntax.
Location:
src/torcontrol.cpp:696(head).🔵 Suggestion · Backslash-workaround configurations need upgrade guidance
Operators who doubled backslashes in -torpassword as a workaround can lose their automatic onion service after upgrading; no affected configuration has been identified.
Location:
src/torcontrol.cpp:696(head).Review coverage was incomplete.
Reviewed:
a00b063137c7· Full review report · Previous reportspermalink
There is already test coverage suggested for this in #35292, please coordinate with the author there how to proceed.
You should install it and then test it.
Installed Tor 0.4.9.12 and tested against it with
HashedControlPasswordforpa\ss"word\: on master bitcoind gets "tor: Authentication failed", with this change authentication succeeds and ADD_ONION creates the service. I'll ask in #35292 how to combine the test coverage.approach ACK
backslashes are not escaped on present
master. to confirm, i ran the test introduced in this PR onmasterand it failed with:test output log
also, i verified that this PR's motivation is valid and is required by the TorControl spec:
from https://spec.torproject.org/control-spec/message-format.html#description-format.
reply-to: https://github.com/bitcoin/bitcoin/pull/36374#issuecomment-5876898982
yes, we had an exchange and reached consensus here: https://github.com/bitcoin/bitcoin/pull/35292#issuecomment-5971847668
since this PR fixes a bug and adds the fix's regression test, while #35292 is test-only, has a larger diff, and covers more test cases, i think it makes sense for this one to go first. it is smaller and should be easier to review, with fewer conflicts with #35292
neither PR depends on the other, so i can rebase on top of this PR. the remaining conflicts should be straightforward to resolve, and i can handle them afterwards as proposed here: https://github.com/bitcoin/bitcoin/pull/35292#issuecomment-5970759968
thanks for bringing this to my attention, @fjahr
nit: this case only asserts the commands received by the mock, and
does not inspect the test node's debug log.
-debug=toronlyenables debug-level logs (not needed in this case) and can be dropped
here
Dropped it in
9c9bd8cab0, thanks. The test still fails on master and passes with the fix.tACK
9c9bd8cab0successfully built and tested with
clang++-19on FreeBSD15.0, targetingx86_64i
git-applyiedfeature_torcontrol.py's patch from this PR onto currentmasterat9dfde64cc3, and the test failed with:output
i also tested on TOR running locally with a
bitcoindbinary built frommasterwith password aspa\ss"word\and it failed with:debug log
then, i tested with this PR's patch applied and i got these logs:
debug log
the TOR daemon version details used (built from source --
mainat84caa7e47b1a60c4):the command i used to run
bitcoind:ACK
9c9bd8cab0Ping for rebase.
Can this be closed for https://github.com/bitcoin/bitcoin/pull/36637 ?
Sure, closing in favor of #36637, which avoids the escaping entirely by sending the password hex-encoded.