net: stop sharing P2P listeners with automatic Tor services

bitcoin/bitcoin: PR #36170

5 suggestions

Earlier concerns neither republished nor resolved: 1 major finding · 2 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Mock-controller tests omit the retained default onion target

The mock-controller tests still omit the no--bind and -whitebind-only paths, although this PR rewrites their target selection and promises to preserve automatic service creation.

Location: test/functional/feature_torcontrol.py:146 (head).

Details and suggested fix

restart_with_mock supplies an explicit onion bind by default, and the framework's bind=127.0.0.1 suppresses the default onion target when no explicit onion bind is supplied. Consequently, these tests cannot catch a regression that retains the default listener but skips ADD_ONION or forwards it elsewhere. Add mock-controller cases without any -bind and with only -whitebind, disabling or overriding the framework bind. Assert that ADD_ONION forwards to 127.0.0.1 at the configured -port plus one, and that a connection there is classified as onion without IP-whitelist permissions.


Link

[suggestion] · tor.md omits the access boundary for non-loopback onion binds

The new remote-Tor guidance omits that, under existing classification behavior, a direct peer reaching the onion bind can learn the node's onion address while knowing its IP.

Location: doc/tor.md:114 (head).

Details and suggested fix

The instruction to configure a reachable onion bind can lead operators to expose that socket beyond the Tor daemon. CreateNodeFromAcceptedSocket identifies incoming Tor traffic solely by the local bind address, not by authenticating the connecting process. A direct peer accepted there is therefore treated as an onion peer and can receive the node's onion self-advertisement. Add a sentence advising operators to restrict access to the Tor daemon, for example with a firewall or private container network, because every accepted connection to that bind is classified as incoming Tor traffic.


Link

[suggestion] · Contract documentation arrives after the Tor behavior changes

The behavior commits leave the controller comment and help text unchanged until the final documentation commit, requiring readers to look ahead to validate the new contract.

Location: src/torcontrol.h:120 at 281c9d985018 (commit) (commit).

Details and suggested fix

At 67420f758a5c82ac8f09a3caa6403310c362acb3, TorController accepts an optional target and can stop after proxy discovery, but its class comment still promises service creation and the help text does not explain the missing-bind case. f4d68cb50b8855f01399c1df744494d379e86f1e similarly introduces wildcard rejection without matching help wording. These are documented later in 281c9d98501836b1cedec2dffb496076377d4f90; this is a series-review concern, not a head defect. Move the controller comment and missing-bind/proxy-discovery help into 67420f758a5c82ac8f09a3caa6403310c362acb3, and document the wildcard prohibition in f4d68cb50b8855f01399c1df744494d379e86f1e. Keep doc/tor.md and the release note in 281c9d98501836b1cedec2dffb496076377d4f90. These text-only moves leave the final behavior unchanged.


Link

[suggestion] · IPv6 wildcard rejection coverage unnecessarily depends on loopback availability

The [::] rejection case is skipped when IPv6 loopback is unavailable, although this argument check needs neither a configured IPv6 interface nor a successful IPv6 bind.

Location: test/functional/feature_bind_extra.py:120 (head).

Details and suggested fix

test_ipv6_local() checks whether an IPv6 socket can reach ::1, but the wildcard InitError occurs before connman->Start. The onion-bind lookup uses AI_NUMERICHOST, not AI_ADDRCONFIG, and IsBindAny() checks only the parsed address bytes. Remove the test_ipv6_local() guard so both wildcard cases exercise the rejection even on hosts without usable IPv6 loopback.


Link

[suggestion] · The outbound-only test never preserves an existing onion key

The current code preserves the cached onion key, but the outbound-only test deletes it first and therefore cannot check identity continuity when a dedicated onion bind is later added.

Location: test/functional/feature_torcontrol.py:220 (head).

Details and suggested fix

test_missing_onion_bind calls restart_with_mock without cached_private_key, causing the fixture to unlink onion_v3_private_key. The existing reuse test also rewrites the file before restarting. Add a fixture mode that leaves the file untouched, then carry a valid cached key through an outbound-only start. Assert that no ADD_ONION is sent and the file remains byte-for-byte unchanged. Restart with a dedicated onion bind without reseeding the file and assert that ADD_ONION uses the same key. This covers the recovery sequence described by the release note.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The motivating problem was operator control over listening sockets: the additional Tor listener could not be disabled independently of ordinary P2P listening. Issue #22726 explicitly required a way to disable the extra bind; its reported workarounds were an intentionally failing onion bind or disabling all listening, the latter also preventing normal binds.

The normal-bind fallback addressed an unwanted extra-listener problem, not a requirement that every explicit P2P bind acquire a second socket. Replacing shared forwarding must distinguish preserving the operator’s selected listeners from preserving automatic incoming Tor service.

Source 1 · Source 2

Dedicated onion listeners were introduced to distinguish incoming Tor connections from ordinary localhost connections. Proposal #19991 provided separate default target ports and the explicit '=onion' bind annotation for that purpose.

Reusing a normal bind retained incoming reachability but bypassed the dedicated-listener distinction. The pinned head instead requires a dedicated onion target for automatic incoming service creation, while retaining the default dedicated target when no normal bind is configured.

Source 1

Automatic service creation and listening for Tor-forwarded connections were historically separate configuration concerns. In #22726, a participant objected that making '-listenonion=0' disable onion listening would break services configured statically in torrc: those services can still require a Bitcoin listener even when Bitcoin Core does not create the service through Tor control.

The compatibility boundary includes manually managed Tor services, not just automatic services. Skipping ADD_ONION is conceptually different from removing configured listening sockets or interpreting '-listenonion=0' as prohibiting all incoming Tor traffic.

Source 1

Ralph's inferences

The fallback combined two compatibility goals: avoid adding the unwanted default onion socket, while continuing automatic incoming Tor service through the first explicitly selected normal P2P listener. Consequently, explicit-normal-bind users could depend on automatic incoming Tor without having configured '=onion'. Outbound-only control is not equivalent for those users; incoming service is the deliberately changed capability.

The base selects the first onion bind, otherwise the first normal bind, otherwise adds the default onion bind. The head removes only the normal-bind target choice. This identifies the affected configuration precisely and explains why restoring incoming service now requires a dedicated onion bind rather than merely retaining control-port connectivity.

Source 1

Outbound proxy discovery is a separate compatibility capability from incoming service creation. In the base, successful control authentication requests Tor's SOCKS listeners unless '-onion' is explicitly configured, before issuing ADD_ONION. The head preserves that request before returning when no incoming target exists.

Absence of a dedicated onion bind does not imply that Tor control has no remaining purpose. Keeping authentication and proxy discovery preserves the existing outbound-discovery path and its explicit '-onion' override, even though automatic incoming service is skipped.

The default-listener compatibility boundary is narrower than 'any explicit listener disables the default onion bind': both pinned versions retain the default onion target when there are no normal or onion binds, including configurations using only whitebind. Explicit onion binds retain priority, with the first selected as the automatic service target.

These configurations did not depend on the normal-bind fallback and remain distinct from the newly outbound-only case. Preserving them avoids conflating removal of shared forwarding with removal of default automatic Tor service or explicit target selection.