Skip to content

net: don’t self advertise tor exit node ip addresses in outbound connections - #35578

Open
stratospher wants to merge 4 commits into
bitcoin:masterfrom
stratospher:2026-05-self-adv-tor-exit
Open

stratospher wants to merge 4 commits into
bitcoin:masterfrom
stratospher:2026-05-self-adv-tor-exit

Conversation

@stratospher

Copy link
Copy Markdown
Contributor
  • During self advertisement in GetLocalAddrFromPeer - we advertise the "IP address we think we are" and sometimes replace it with what "IP address the peer thinks we are".
  • when an outbound connections is made to a peer via a proxy, the "IP address the peer thinks we are" is the proxy's ip address.
  • so the proxy's ip address can get relayed as our self advertisement
  • in normal cases the proxy's ip address is not a reachable inbound address and shouldn't be relayed on the network.

Example: when a node running both Tor and clearnet via a SOCKS5 proxy connects to a clearnet peer (proxy=127.0.0.1:9050, listen=1, discover=1 (or) onion=127.0.0.1:9050), the "IP address the peer thinks we are" is the Tor exit node's IP address and doesn't make sense to relay it. 55-76% of all tor exit nodes were present in various addrman snapshots I checked (my node and the ones from b10c’s peer.observer) from now and few years ago. would be nice to not unnecessarily relay these tor exit IPs since they end up being stored as fresh and gossiped from multiple sources entries in our addrman.

an advanced node runner might have a proxy whose ip address is also a reachable inbound address. I've personally not used such a proxy but 1 difference for them is that they'd need to explicitly set -externalip=<addr> to self-advertise their proxy address. i feel it’s an acceptable tradeoff and would imagine they are already using -externalip=<addr> config flag as they are explicitly managing their node's public address.

@DrahtBot DrahtBot added the P2P label Jun 21, 2026
@DrahtBot

DrahtBot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

Type Reviewers
Concept ACK 0xB10C, naiyoma, mzumsande

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

@0xB10C

0xB10C commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Concept ACK, it makes sense to me to not advertise an address we know we can't be reached on. I think this is the case when using -proxy, as we specifically say "make outbound connections through this SOCKS5" but don't expect inbound connections via this socket. There seems to be something called BIND-request for SOCKS5 proxies, but I don't think that's widely supported (and not implemented in Bitcoin Core).

I've looked at the number of connections my nodes make to Tor exit node IPs in this post: In mid 2026, my nodes each make between 7.5 to 12.5 connection attempts per day to Tor exit node IPs.

While nearly all of these connection attempts fail (as expected), there's about 20 IPs where I've seen some connections to Tor exit node IPs succeed over the last years. I assume these are hosts that run (or ran at some point) a Tor exit node and a Bitcoin node, which isn't too unexpected.

@0xB10C

0xB10C commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

proxy=127.0.0.1:9050, listen=1, discover=1

Hm are we sure this is being used like this? With just -proxy set, we wouldn't be listening and not self-announcing.

bitcoin/src/init.cpp

Lines 812 to 825 in 93012d7

std::string proxy_arg = args.GetArg("-proxy", "");
if (proxy_arg != "" && proxy_arg != "0") {
// to protect privacy, do not listen by default if a default proxy server is specified
if (args.SoftSetBoolArg("-listen", false))
LogInfo("parameter interaction: -proxy set -> setting -listen=0\n");
// to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
// to listen locally, so don't rely on this happening through -listen below.
if (args.SoftSetBoolArg("-natpmp", false)) {
LogInfo("parameter interaction: -proxy set -> setting -natpmp=0\n");
}
// to protect privacy, do not discover addresses by default
if (args.SoftSetBoolArg("-discover", false))
LogInfo("parameter interaction: -proxy set -> setting -discover=0\n");
}

bitcoin/src/net_processing.cpp

Lines 5475 to 5476 in 93012d7

// Periodically advertise our local address to the peer.
if (fListen && !m_chainman.IsInitialBlockDownload() &&

@stratospher

Copy link
Copy Markdown
Contributor Author

proxy=127.0.0.1:9050, listen=1, discover=1

Hm are we sure this is being used like this? With just -proxy set, we wouldn't be listening and not self-announcing.

good point. it's either this or people using onion=127.0.0.1:9050.

even though there is the soft-set init parameter interactions which does proxy=127.0.0.1:9050 -> listen=0 and discover=0 - I wouldn't be surprised if people end up overriding it.

  • listen=1 is overriden to allow inbound connections without having to deal with the clearnet firewall rules. I've seen/done this a lot.
  • I think discover=1 and its interaction with other parameters can be confusing to users. It makes a node's own IP discoverable to peers (the node advertises it). That IP is obtained from the node's own machine, and (less obviously) also from what peers report the node's address to be.
    • If the node wants control over what exactly it advertises, -externalip=<ip> can be used (keeping the soft-set discover=0) - the node then advertises only the address we specified in externalip, and not the peer-reported view of a node's IP.
    • if -externalip=<ip> is used with explicit discover=1 override in the bitcoin.conf then again the peer-report view of a node's ip can be advertised.

quick GitHub search shows proxy=127.0.0.1:9050, listen=1, discover=1 use here and here. unsure if it's common/rare/how many people use it like this though.

@naiyoma

naiyoma commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Concept ACK
It makes sense not to advertise these addresses, as they are not useful.
i used this list https://check.torproject.org/torbulkexitlist to check for tor exit nodes.

On master, I noticed that sometimes clearnet outbound peers would send me their own addresses as my address, and I would occasionally self-advertise those same addresses back to them. I think this PR fixes that only for proxy, but maybe we should also add check so that a peer does not send us their own address.

tested 412aa3d with listen=1 proxy=127.0.0.1:9050 discover=1

My logs show that even when the score flip favoured the peers reported address for an outbound clearnet (tor_proxied ) peer , we do not advertise it , instead we now always fallback to advertising our own adress that we know.

Logs
2026-07-10T13:12:40Z New outbound-full-relay peer connected: transport: v2, version: 70016, peer=4, peeraddr=91.67.73.147:8333
2026-07-10T13:12:40Z [net] sending sendcmpct (9 bytes) peer=4
2026-07-10T13:12:40Z [net] sending ping (8 bytes) peer=4
2026-07-10T13:12:40Z [net] Maybe we should self announce to this address relay peer 4, relay_enabled=1, fListen=1, next_local_addr_send=0, current_time=1783689160359904
...
2026-07-10T13:12:40Z [net] GetLocalAddrForPeer peer=4: ours=[2605:59c1:4782:7c08:4936:c6a5:fdee:50d2]:8333 (routable=1) peer_reported=185.220.101.24:43126 (routable=1) | peer_good=1 own_unroutable=0 own_score=1 LOCAL_MANUAL=4 flip_bits=1 (1-in-2) won_flip=1 -> using peer's addrLocal
2026-07-10T13:12:40Z [net] Advertising address [2605:xxx:xx:xxx:xx:xx:xx]:8333 to peer=4

Comment thread src/net.cpp Resolved
Comment thread src/net.cpp Resolved

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

I wonder if it is really all explained by misconfigurations, overriding defaults, and if everyone would be running this branch, the exit nodes would stop being relayed.

Maybe it could also due to transparent torification where users do not change any defaults but the traffic is rerouted via tor externally, e.g. by an OS such as Whonix? In that case, the fix might not solve the problem completely.

@sedited

sedited commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@stratospher what is the status here? There are a few unaddressed comments.

@stratospher

Copy link
Copy Markdown
Contributor Author

@mzumsande good point! I don't think we have a way to know unless we see it in action in the P2P network and this patch obviously won't work for systems running transparent torrification. but we can try to reduce it from core's end when people override defaults.

even though it's not a problem currently, ~95% of the tor exit IPs don't have ports in p2p-bad-ports.md. some examples: 1031 tor exit IPs on port 443 (I vaguely remember some discussion on 443 being a good option for core as well), 705 tor exit IPs on port 9001, 276 tor exit IPs on port 9002.

if we ever switch to non default ports - it might get problematic for the tor exits. so I think it's still good to reduce unnecessary connection attempts to tor exits from our side (this is not an issue currently).

@stratospher

Copy link
Copy Markdown
Contributor Author

CI failure is unrelated. could someone start the failed CI job again? thanks!
the latest push adds tests, a comment and a release note.

@DrahtBot DrahtBot closed this Sep 17, 2026
@DrahtBot DrahtBot reopened this Sep 17, 2026
@stratospher
stratospher force-pushed the 2026-05-self-adv-tor-exit branch from d7e3ec6 to 38f2716 Compare October 20, 2026 20:29
@stratospher

Copy link
Copy Markdown
Contributor Author

looks like b403937 was done in #36177. I've removed it.

When outbound connections to clearnet peers are made via a proxy,

- During self advertisement - we advertise
  "IP address we think we are" and sometimes replace it with what
  "IP address the peer thinks we are".
- the "IP address the peer thinks we are" is the proxy's ip address.
  and can get relayed as our self advertisement
- in normal cases the proxy's ip address is not a reachable inbound
  address and shouldn't be relayed on the network.

there is a soft-set init parameter interaction proxy → discover=0
to prevent this situation but don't think it works in practice
because people might end up overriding it with discover=1
in real life, 55-76% of all tor exit nodes were present in
various addrman snapshots from now and few years ago. so would be
nice to check when behind a proxy before self advertising.
a unit test that sets a proxy would leak it into later cases
in the same binary without a ResetProxy function.
With a proxy set, check that when we make an:
- outbound: the peer's view of us is the proxy's address, so it is no
  longer used and nothing is advertised
- inbound: unaffected, no proxy is involved and the peer does observe
  our own address
- -externalip: still advertised
add a note for advanced operators who want to run reachable proxies
(ex: tor exits and bitcoin nodes)
@stratospher
stratospher force-pushed the 2026-05-self-adv-tor-exit branch from 38f2716 to 3c6293a Compare November 17, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants