AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
High 70 Bitcoin

Merge bitcoin/bitcoin#36142: net: validate Tor onion service replies and cached keys

Public commit record

What the developer wrote

Authored by merge-script

96/100 · Strong
Merge bitcoin/bitcoin#36142: net: validate Tor onion service replies and cached keys

0a53d12589c3116495a50a694006ce5ee220fb2d torcontrol: reject invalid service IDs (Lőrinc)
d0b447cf7f11d791622c919d2a0731bf33a7d33f torcontrol: validate returned and cached keys (Lőrinc)
3413d17028da5f5658af5637297013f8e396bafa torcontrol: discard replies missing a service ID (Lőrinc)
3601a1d1086b132f11db3b5e969d8fac9203decc test: characterize ADD_ONION reply handling (Lőrinc)
d63a8576d9beef910c54aabc388278897c16a41f refactor: prepare ADD_ONION validation (Lőrinc)

Pull request description:

**Problem:** A node creates its onion service through Tor's control protocol and caches the returned `PrivateKey` value for reconnects.
Tor reply parsing unescapes quoted values, so a control endpoint can return a value containing a line break or space.
On reconnect, the node inserts that value unquoted into an `ADD_ONION` command.
CRLF frames the remainder as a separate command, while a space adds further arguments.
An unprivileged local process can exploit this by impersonating the default loopback endpoint while Tor is unavailable, seeding the cache, and releasing the port before Tor is available again.
A compromised operator-configured endpoint can return the same malicious value.
The reply handler also continues after receiving an invalid service ID, logging it and caching the key before attempting to advertise the invalid address.
A later reply without a service ID can reuse an ID left by an earlier reply.

**Fix:** This PR validates the returned service ID as a Tor v3 onion address before logging it, caching the key, or advertising the service.
Each reply must provide its own service ID, and reply fields stay local until validation succeeds.
Key validation accepts `NEW:ED25519-V3` or an `ED25519-V3` key whose Base64 payload decodes to 64 bytes.
Returned keys are validated before adoption or caching, and cached keys are validated before reuse.
A malformed cached key leaves the onion service unavailable until the operator removes the file and restarts the node. It cannot inject another command or argument.

ACKs for top commit:
jpk68:
ACK 0a53d12589c3116495a50a694006ce5ee220fb2d
vasild:
ACK 0a53d12589c3116495a50a694006ce5ee220fb2d
winterrdog:
tACK 0a53d12589c3116495a50a694006ce5ee220fb2d
sedited:
ACK 0a53d12589c3116495a50a694006ce5ee220fb2d

Tree-SHA512: ce3d75da56d9d2ef52655c15b8c85995cdec38305abc4c7af6baf45e03288e08e8ab13b67925b8f1c0a0734ae062101cb2bb912e962b517b8f99ee0e9911f882
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This update fixes a weakness in how Bitcoin Core talks to the Tor control port when setting up a hidden onion service. A fake or compromised Tor control endpoint could trick the node into storing a malicious private key. On a later reconnect, that bad key could be inserted into an 'ADD_ONION' command in a way that adds extra commands or arguments for Tor to run. The fix checks that any returned or cached private key has the expected format and that the returned onion address is a valid Tor v3 service ID before using or saving it.

Recommended action

Apply the merge commit. Nodes that expose a Tor onion service should upgrade, because an unprivileged local process or a compromised Tor control endpoint could otherwise inject commands into the Tor control session. Operators using -torcontrol with non-default endpoints should also verify endpoint integrity.

Security signals we found

01

Tor control protocol command/argument injection via unescaped quoted reply values

02

Insufficient validation of attacker-influenced private key before caching and reuse

03

Insufficient validation of returned onion service ID before adoption and advertisement

04

Local privilege escalation/persistence by impersonating the Tor control endpoint on loopback

05

Cross-session cache poisoning of onion private key file

Risk score

Why this scored 70/100

Our methodology →
Potential impact 22/30
Exploitability 16/25
Stealth signal 10/15
Affected reach 8/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.