Skip to content

net: Warn when Tor onion service lacks a dedicated onion bind - #34892

Closed
HouseOfHufflepuff wants to merge 1 commit into
bitcoin:masterfrom
HouseOfHufflepuff:net-warn-bind-missing-onion-socket
Closed

HouseOfHufflepuff wants to merge 1 commit into
bitcoin:masterfrom
HouseOfHufflepuff:net-warn-bind-missing-onion-socket

Conversation

@HouseOfHufflepuff

@HouseOfHufflepuff HouseOfHufflepuff commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When -bind is specified without a dedicated onion socket (-bind=<addr>=onion) but -listenonion is enabled, the auto-created Tor hidden service routes incoming connections to the regular bind address. This makes it impossible to distinguish incoming Tor connections from regular IPv4 connections, causing -netinfo to report 0 onion connections even when they exist.

This adds a startup warning to alert users so they can add -bind=127.0.0.1:8334=onion for accurate connection tracking.

Fixes #33458

Test plan

Start bitcoind with -bind but without a dedicated onion bind:

./build/bin/bitcoind -bind=0.0.0.0:8333 -listenonion=1

Before this change: No warning is emitted. Users have no indication that incoming Tor connections will be misidentified.

After this change: A warning is printed at startup:

Warning: The Tor onion service is being directed to a -bind address without a dedicated onion socket (-bind=<addr>=onion). Incoming Tor connections will not be identified as onion connections.

The warning does not appear when a dedicated onion bind is provided:

./build/bin/bitcoind -bind=0.0.0.0:8333 -bind=127.0.0.1:8334=onion -listenonion=1

Functional test feature_proxy.py updated to expect the new warning.

@DrahtBot DrahtBot added the P2P label Mar 22, 2026
@DrahtBot

DrahtBot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34892.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK winterrdog, jpk68

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:

  • #36170 (net: require a dedicated bind for automatic Tor by l0rinc)
  • #34486 (net: Reduce local network activity when networkactive=0 by willcl-ark)

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.

@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

@ArmchairCryptologist

@kevkevinpal

Copy link
Copy Markdown
Contributor

Looks like the functional test feature_proxy.py is failing

You can fix it by modifying this bit of code to looks like this

self.log.info("Test passing -onlynet=onion without -proxy or -onion but with -listenonion=1 is ok")
self.start_node(1, extra_args=["-onlynet=onion", "-listenonion=1"])
- self.stop_node(1)
+ self.stop_node(1, expected_stderr="Warning: The Tor onion service is being directed to a -bind address without a dedicated on  ion socket (-bind=<addr>=onion). Incoming Tor connections will not be identified as onion connections.")

@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

Thanks @kevkevinpal! Good catch — applied the fix to feature_proxy.py to pass expected_stderr with the new warning message on stop_node. Test passes locally now. Ready for re-review.

@maflcko

maflcko commented Mar 24, 2026

Copy link
Copy Markdown
Member

Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

Also, the test plan is clearly wrong.

Was this LLM generated? What are the steps to test this? What is the output before and after the changes here?

@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

Sorry about that @maflcko — you're right, the test plan was inadequate and there were unrelated changes that shouldn't have been in the branch. I've squashed into a single commit, removed the unrelated changes, and updated the PR description with actual before/after output. Should be ready for another look when you have time.

@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch from 97bcdad to bfb2401 Compare March 24, 2026 14:41
@kevkevinpal

Copy link
Copy Markdown
Contributor

I think it would be good to add a test asserting that this warning gets logged. In addition to modifying the existing test that was failing.

@maflcko

maflcko commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

You'll have to run the tests locally before pushing to CI

@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch 2 times, most recently from c33d92a to 2e63783 Compare March 25, 2026 20:08
@HouseOfHufflepuff

HouseOfHufflepuff commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@maflcko Apologies for the messy state earlier — commits are squashed, unrelated changes removed, and tests verified locally before pushing. Lesson learned on the workflow. Ready for re-review whenever you have time.

@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

@kevkevinpal Thanks for the proxy test catch and the suggestion to add a warning assertion — both are addressed now. CI is passing clean. Would appreciate another look when you have a moment.

@naiyoma naiyoma 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.

I’m not sure about this approach. I think the right direction would be to try to get the count right. I’ve explained what I think the two options might be -> #33458 (comment)

@naiyoma

naiyoma commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

I’m not sure about this approach. I think the right direction would be to try to get the count right. I’ve explained what I think the two options might be -> #33458 (comment)

I was wrong about the alternative approaches I suggested. I don't think we can get the correct count. This approach is fine.

Comment thread test/functional/feature_proxy.py Outdated
@@ -436,6 +436,17 @@ def networks_dict(d):

self.log.info("Test passing -onlynet=onion without -proxy or -onion but with -listenonion=1 is ok")
self.start_node(1, extra_args=["-onlynet=onion", "-listenonion=1"])
self.stop_node(1, expected_stderr="Warning: The Tor onion service is being directed to a -bind address without a dedicated onion socket (-bind=<addr>=onion). Incoming Tor connections will not be identified as onion connections.")

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.

Nit: IMO this test would be better placed in feature_bind_extra.py rather than in this file.
feature_bind_extra.py also sets bind_to_localhost_only = False, meaning we can explicitly control -bind configuration and not rely on the default.
I initially found it confusing why the test was passing, and then I realized that by default, bind_to_localhost_only is true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, moved and using explicit bind.

@naiyoma

naiyoma commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

and when using -netinfo it should show a "?" or "-" instead of "0".

This is a good suggestion from the issue have you considered implementing it?

@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch 2 times, most recently from 9a2fd75 to f23b35a Compare March 30, 2026 14:42
@HouseOfHufflepuff

HouseOfHufflepuff commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review @naiyoma!

Moved the warning tests from feature_proxy.py to feature_bind_extra.py where bind_to_localhost_only = False gives us explicit control over -bind configuration. The tests now pass explicit -bind args so it's clear why the warning fires (or doesn't). The -onlynet=onion -listenonion=1 test stays in feature_proxy.py since it's testing the onlynet behavior, and just handles the warning as expected stderr.

Re: showing "?" or "-" instead of "0" in -netinfo — that's a good idea from the original issue, but I think it's better suited as a follow-up PR since it touches different code (-netinfo output formatting in bitcoin-cli). Happy to open an issue and work if you would like. Happy to do here as well but wanted to check.

Comment thread src/init.cpp Resolved
@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch 2 times, most recently from dc708ab to 716812b Compare April 28, 2026 03:22
@winterrdog

winterrdog commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Could someone re-run those jobs?

perhaps the day you pushed these changes, github had run into reliability issues thus returning a timeout. so i think a small hack you can use to re-trigger the CI is to amend the last commit:

git commit --amend --no-edit
git push --force-with-lease

it won’t add extra commits, so no need to squash later. if it fails twice in the same way, stop retrying and treat it as a real issue in the test or environment.

@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch from 716812b to 7025bf3 Compare April 30, 2026 22:29
@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

Could someone re-run those jobs?

perhaps the day you pushed these changes, github had run into reliability issues thus returning a timeout. so i think a small hack you can use to re-trigger the CI is to amend the last commit:

git commit --amend --no-edit
git push --force-with-lease

it won’t add extra commits, so no need to squash later. if it fails twice in the same way, stop retrying and treat it as a real issue in the test or environment.

Thank you. I re-ran and CI is green.

Comment thread test/functional/feature_torcontrol.py Outdated
@@ -107,6 +108,7 @@ def _get_response(self, command):
class TorControlTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [[f"-bind=127.0.0.1:{tor_port(0)}=onion"]]

@winterrdog winterrdog May 2, 2026 •

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.

i think this extra_args property can be removed in favour of the one on line 123. this is because it has no clear effect on the tests (actually they pass perfectly, even without it)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed, you're right it's redundant.

Comment thread test/functional/feature_proxy.py Outdated
@@ -436,7 +436,7 @@ def networks_dict(d):

self.log.info("Test passing -onlynet=onion without -proxy or -onion but with -listenonion=1 is ok")
self.start_node(1, extra_args=["-onlynet=onion", "-listenonion=1"])

@winterrdog winterrdog May 2, 2026 •

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.

i think we're not very interested in testing for the warning's presence here as much as we do in feature_bind_extra.py. for that reason, we can pass an explicit -bind here in order to avoid triggering the warning's condition introduced by the PR's init.cpp

Suggested change
self.start_node(1, extra_args=["-onlynet=onion", "-listenonion=1"])
self.start_node(1, extra_args=["-onlynet=onion", "-listenonion=1", f"-bind=127.0.0.1:{tor_port(1)}=onion"])

i think this will fulfill @naiyoma's nit and also prevents tight coupling in the tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, passing explicit bind now.

@@ -534,6 +534,10 @@ def set_tx_returner_and_other():
assert_raises_rpc_error(-1, "none of the Tor or I2P networks is reachable",
tx_originator.sendrawtransaction, hexstring=txs[0]["hex"], maxfeerate=0.1)

# Restart node 0 with original args so that cleanup does not fail due to
# the warning about missing dedicated onion bind on stderr.
self.restart_node(0, expected_stderr="Warning: The Tor onion service is being directed to a -bind address without a dedicated onion socket (-bind=<addr>=onion). Incoming Tor connections will not be identified as onion connections.")

@winterrdog winterrdog May 2, 2026 •

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.

even here, it'll be similar to what i suggested here. we can pass an explicit -bind just below line 532.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, passing explicit bind now.

@winterrdog winterrdog 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.

@HouseOfHufflepuff
tested and left some review comments for you.

@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch from 7025bf3 to cc1bf1d Compare May 2, 2026 01:05
@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

@HouseOfHufflepuff tested and left some review comments for you.

Thank you. I have addressed the comments with the suggested implementation.

@winterrdog

Copy link
Copy Markdown
Contributor

Re-ACK cc1bf1d

@sedited

sedited commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

@naiyoma can you take another look here?

@naiyoma

naiyoma commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Sorry, I was AFK. I'll re-review soon

@winterrdog

winterrdog commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

@HouseOfHufflepuff

i think you will need to edit the commit message and remove Anthropic's Claude as a co-author. a recent AI policy was passed saying that LLMs are just tools, so they should not be credited as co-authors

if there were other contributors, they can be added as co-authors; otherwise, the Co-Authored-By field can just be left out entirely


also, i think the commit message could be trimmed down. right now it repeats the PR description almost line-for-line, and since the merge script folds the full PR description into the merge commit anyway, having both means the same explanation ends up duplicated in permanent history. a shorter commit message focused on the "what/why" would be enough.

sth like (you are completely free to modify it into what you want):

net: Warn when Tor onion service lacks a dedicated onion bind

When -bind is specified without a dedicated -bind=<addr>=onion, the
auto-created Tor hidden service routes incoming connections to the
regular bind address, making it impossible to distinguish incoming
Tor connections from regular ones (-netinfo reports 0 onion
connections even when they exist).

Warn at startup when listenonion is set but no dedicated onion bind
is configured, so users can add -bind=127.0.0.1:8334=onion for
accurate connection tracking.

Update functional tests to cover the new warning and to pass an
explicit onion bind where the warning would otherwise be spurious.

Fixes #33458

When -bind is specified without a dedicated -bind=<addr>=onion, the
auto-created Tor hidden service routes incoming connections to the
regular bind address, making it impossible to distinguish incoming
Tor connections from regular ones (-netinfo reports 0 onion
connections even when they exist).

Warn at startup when listenonion is set but no dedicated onion bind
is configured, so users can add -bind=127.0.0.1:8334=onion for
accurate connection tracking.

Update functional tests to cover the new warning and to pass an
explicit onion bind where the warning would otherwise be spurious.

Fixes bitcoin#33458
@HouseOfHufflepuff
HouseOfHufflepuff force-pushed the net-warn-bind-missing-onion-socket branch from cc1bf1d to 4736431 Compare July 27, 2026 14:01
@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

@HouseOfHufflepuff

i think you will need to edit the commit message and remove Anthropic's Claude as a co-author. a recent AI policy was passed saying that LLMs are just tools, so they should not be credited as co-authors

if there were other contributors, they can be added as co-authors; otherwise, the Co-Authored-By field can just be left out entirely

also, i think the commit message could be trimmed down. right now it repeats the PR description almost line-for-line, and since the merge script folds the full PR description into the merge commit anyway, having both means the same explanation ends up duplicated in permanent history. a shorter commit message focused on the "what/why" would be enough.

sth like (you are completely free to modify it into what you want):

net: Warn when Tor onion service lacks a dedicated onion bind

When -bind is specified without a dedicated -bind=<addr>=onion, the
auto-created Tor hidden service routes incoming connections to the
regular bind address, making it impossible to distinguish incoming
Tor connections from regular ones (-netinfo reports 0 onion
connections even when they exist).

Warn at startup when listenonion is set but no dedicated onion bind
is configured, so users can add -bind=127.0.0.1:8334=onion for
accurate connection tracking.

Update functional tests to cover the new warning and to pass an
explicit onion bind where the warning would otherwise be spurious.

Fixes #33458

I have removed this. Thank you.

@winterrdog winterrdog 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.

reACK 4736431

ZERO code changes were made between this commit and the previous one. only the commit message was edited to cut back on the verbosity thus changing the commit hash as a result

@jpk68

jpk68 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

ACK 4736431

@vasild

vasild commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

The warning seems like an improvement over master. However I think this new warning should be a startup error instead.

bitcoind will not function properly if it cannot distinguish incoming Tor connections from non-Tor incoming connections. Before I was thinking that this improper functioning is benign if the user happens to configure it that way. The recent wave of creative AI-assisted security discoveries however makes me think that we better forbid such an improper operation right away instead of only warning about it or chasing all of its aspects one by one (and forget some). One aspect is incoming Tor connections unexpectedly getting whitelist permissions. Another is that we try to keep one connection to each network and do bucketing / subnetting trying to have a diverse set of connections. This is for outbounds but that logic is easily messed if we treat Tor as IPv4 for example. Another is the netinfo counting discussed above.

Sounds much safer to me to just refuse to start with a config like -bind=... -listenonion=1 (without -bind=...=onion). Such a setup is somewhat harmful and has zero value IMO. Give the user two options:

  1. if incoming Tor connections are desired: add -bind=...=onion
  2. if incoming Tor connections are not desired: disable listenonion: -listenonion=0

If the onion service is configured statically from torrc to point to the regular P2P listening port of bitcoind, then this messup of Tor and IP connections will still happen because then bitcoind is genuinely unaware that Tor is involved at all in its setup. But nevertheless, better to harden/strengthen this for the scenarios we are aware of it.

@l0rinc

l0rinc commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Added an alternative based on @vasild's suggestions here, added him and this author as coauthors: #36170

@HouseOfHufflepuff

Copy link
Copy Markdown
Contributor Author

Closing in favor of #36170, which implements the hard-error approach suggested by @vasild and carries forward the detection logic and tests from here (credited as coauthor). Thanks everyone for the reviews on this one — @naiyoma, @kevkevinpal, @winterrdog, @maflcko, @jpk68.

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.

Documentation trap when using -bind in conjunction with (automatically configured) Tor hidden services

10 participants