net: stop sharing P2P listeners with automatic Tor services #36170

pull l0rinc wants to merge 6 commits into bitcoin:master from l0rinc:l0rinc/identify-tor-shared-binds changing 7 files +150 −31
  1. l0rinc commented at 9:25 PM on September 4, 2026: contributor

    Problem: With a normal -bind (but no dedicated onion bind), automatic Tor services can forward incoming connections to the normal P2P listener, where they may be misclassified and inherit IP-based whitelist permissions.

    Fix: If no dedicated onion bind exists, keep Tor control available for outbound proxy discovery but skip automatic incoming service creation and warn after authentication. The node starts with its configured listeners (including the default onion listener when no -bind is supplied), and Tor control starts only after those listeners have been opened successfully.

    Affected nodes need a concrete -bind=<addr>:<port>=onion to restore incoming Tor connections.

    Wildcard onion binds are rejected at startup when -listenonion is enabled, while their classification with -listenonion=0 remains outside this change.

  2. DrahtBot added the label P2P on Sep 4, 2026
  3. DrahtBot commented at 9:25 PM on September 4, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    Concept ACK jeanpablojp
    Stale ACK vasild, jpk68, winterrdog

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36880 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36880.svg"></sub> (init: Fix surprising behaviors of negated options by fjahr)
    • #36861 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36861.svg"></sub> (Configuration argument handling improvements. by jlopp)
    • #36637 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36637.svg"></sub> (torcontrol: send -torpassword hex-encoded to avoid escaping bugs by jpk68)
    • #36257 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equals -> assert_true/assert_false by hodlinator)
    • #35027 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35027.svg"></sub> (net: add -outboundbind option for outgoing source address by 8144225309)
    • #31260 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31260.svg"></sub> (scripted-diff: Type-safe settings retrieval by ryanofsky)
    • #17783 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17783.svg"></sub> (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
    • #17581 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17581.svg"></sub> (refactor: Remove settings merge reverse precedence code by ryanofsky)
    • #17580 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17580.svg"></sub> (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
    • #17493 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/17493.svg"></sub> (util: Forbid ambiguous multiple assignments in config file by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. jeanpablojp commented at 12:55 AM on September 6, 2026: contributor

    Concept ACK

    0.0.0.0 is the default for -bind itself, and -bind=0.0.0.0:8334=onion passes the new check while tagging nothing. addr_bind comes from GetBindAddress on the accepted socket, so what CreateNodeFromAcceptedSocket compares against m_onion_binds is the concrete address the peer reached.

    Same node, same arriving address, same -whitelist. With -bind=0.0.0.0:P=onion the inbound peer is classified by its IP network in getpeerinfo and keeps its noban. Spelling that same address out instead of the wildcard gives onion with no permissions. [::] is classified the same way, and either wildcard is what reaches Tor as the ADD_ONION target.

    Rejecting a wildcard onion bind would close that. Naming 127.0.0.1:8334=onion in the message would only make it less likely. Is the first one in scope here?

  5. in doc/release-notes-36170.md:9 in 7fb68e3927
       0 | @@ -0,0 +1,9 @@
       1 | +P2P and network changes
       2 | +-----------------------
       3 | +
       4 | +Nodes configured with `-bind` but no dedicated `-bind=<addr>=onion` now refuse
       5 | +to start when `-listenonion` is enabled, which is the default when listening.
       6 | +A shared bind cannot distinguish Tor-forwarded connections from direct connections,
       7 | +which can grant Tor peers unintended IP-based whitelist permissions.
       8 | +Users should add a dedicated onion bind to accept incoming Tor connections, or set
       9 | +`-listenonion=0` to disable automatic onion service creation.
    


    jeanpablojp commented at 12:55 AM on September 6, 2026:

    The release note covers upgraders. For someone setting Tor up from scratch, the -bind help advertises default: 127.0.0.1:8334=onion, which still holds with no explicit -bind but not once one is given, and section 2 of doc/tor.md does not mention the dedicated bind. Would a line in one of the two be worth it?


    l0rinc commented at 5:17 AM on September 24, 2026:

    Thanks, added this to both the -bind help and section 2 of doc/tor.md. They now explain when the default onion bind is added and when an explicit, non-wildcard =onion bind is required.

  6. in test/functional/feature_bind_extra.py:103 in 7fb68e3927
      96 | @@ -95,6 +97,14 @@ def run_test(self):
      97 |  
      98 |          self.stop_node(0)
      99 |  
     100 | +        self.log.info("Test -listenonion with a normal bind and no dedicated onion bind")
     101 | +        self.stop_node(2)
     102 | +        assert_raises(FailedToStartError, self.start_node, 2, extra_args=self.expected[2][0] + ["-listenonion=1"])
     103 | +        self.nodes[2].wait_until_stopped(expected_ret_code=1, expected_stderr=re.compile("Tor onion service cannot share"))
    


    jeanpablojp commented at 12:55 AM on September 6, 2026:

    nit: this could use the helper the file already uses further down, and then re, assert_raises and FailedToStartError drop out of the imports. It does loosen the exit status from exactly 1 to any non-zero. Ran it that way and it passes.

            self.nodes[2].assert_start_raises_init_error(
                        self.expected[2][0] + ["-listenonion=1"],
                        "Error: The Tor onion service cannot share a -bind address",
                        match=ErrorMatch.PARTIAL_REGEX)
    

    l0rinc commented at 5:18 AM on September 24, 2026:

    Switched to assert_start_raises_init_error, thanks.

  7. winterrdog commented at 7:12 AM on September 8, 2026: contributor

    Approach ACK

  8. l0rinc force-pushed on Sep 24, 2026
  9. l0rinc commented at 5:19 AM on September 24, 2026: contributor

    Rejecting a wildcard onion bind would close that. Naming 127.0.0.1:8334=onion in the message would only make it less likely. Is the first one in scope here?

    Thanks , added a wildcard-bind check and test (added you as coauthor), but I’d appreciate a second look from e.g. @vasild who has more experience with this part of the networking code than I do.

  10. in test/functional/feature_bind_extra.py:101 in 69116ee97c
      94 | @@ -95,12 +95,28 @@ def run_test(self):
      95 |  
      96 |          self.stop_node(0)
      97 |  
      98 | +        self.log.info("Test -listenonion with a normal bind and no dedicated onion bind")
      99 | +        self.stop_node(2)
     100 | +        self.nodes[2].assert_start_raises_init_error(
     101 | +            self.expected[2][0] + ["-listenonion=1", "-torcontrol=127.0.0.1:1"],
    


    vasild commented at 11:31 AM on October 1, 2026:
                self.extra_args[2] + ["-listenonion=1", "-torcontrol=127.0.0.1:1"],
    

    (not tested)

  11. in test/functional/feature_bind_extra.py:106 in 69116ee97c
     101 | +            self.expected[2][0] + ["-listenonion=1", "-torcontrol=127.0.0.1:1"],
     102 | +            "Error: The automatic Tor onion service requires a dedicated onion bind when -bind is set. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0.",
     103 | +        )
     104 | +
     105 | +        self.log.info("Test -bind with dedicated onion bind starts when -listenonion=1")
     106 | +        self.restart_node(1, extra_args=self.expected[1][0] + ["-listenonion=1", "-torcontrol=127.0.0.1:1"])
    


    vasild commented at 11:32 AM on October 1, 2026:
            self.restart_node(1, extra_args=self.extra_args[1] + ["-listenonion=1", "-torcontrol=127.0.0.1:1"])
    

    (not tested)

  12. in src/init.cpp:1066 in 69116ee97c
    1061 | @@ -1060,6 +1062,11 @@ bool AppInitParameterInteraction(const ArgsManager& args)
    1062 |          return InitError(Untranslated("Cannot set -listen=0 together with -listenonion=1"));
    1063 |      }
    1064 |  
    1065 | +    const auto binds{args.GetArgs("-bind")};
    1066 | +    if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION) && binds.size() && std::ranges::none_of(binds, [](auto& b) { return b.ends_with("=onion"); })) {
    


    vasild commented at 11:38 AM on October 1, 2026:
        if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION) && !binds.empty() && std::ranges::none_of(binds, [](auto& b) { return b.ends_with("=onion"); })) {
    

    l0rinc commented at 5:34 AM on October 7, 2026:

    I prefer non-negated versions, it was deliberate

  13. in src/init.cpp:1067 in 69116ee97c
    1061 | @@ -1060,6 +1062,11 @@ bool AppInitParameterInteraction(const ArgsManager& args)
    1062 |          return InitError(Untranslated("Cannot set -listen=0 together with -listenonion=1"));
    1063 |      }
    1064 |  
    1065 | +    const auto binds{args.GetArgs("-bind")};
    1066 | +    if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION) && binds.size() && std::ranges::none_of(binds, [](auto& b) { return b.ends_with("=onion"); })) {
    1067 | +        return InitError(_("The automatic Tor onion service requires a dedicated onion bind when -bind is set. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."));
    


    vasild commented at 11:45 AM on October 1, 2026:
            return InitError(_("The automatic Tor onion service requires a dedicated onion bind. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."));
    

    With this PR the automatic Tor service requires a dedicated bind, always, unconditionally. Not only "when -bind is set".

    To clarify - if the user did not set -bind, then the defaults do provide both -bind and -bind=...=onion.

  14. in src/init.cpp:2281 in 69116ee97c outdated
    2284 |      }
    2285 |  
    2286 |      if (listenonion) {
    2287 | +        if (connOptions.onion_binds.empty()) {
    2288 | +            return InitError(_("The automatic Tor onion service requires a dedicated onion bind when -bind is set. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."));
    2289 | +        }
    


    vasild commented at 12:17 PM on October 1, 2026:

    Isn't this check redundant? Seems to be the same as the added check in AppInitParameterInteraction(). Better have just one. I prefer this one because it uses connOptions.onion_binds. The other one manually "parses" the arguments and checks for =onion suffix which is redundant with the code that sets connOptions.onion_binds. That is, if =onion would have to be changed to e.g. to support case insensitive match, then it would have to be changed in two places, not nice.


    l0rinc commented at 5:30 AM on October 7, 2026:

    I originally added it to reject the configuration before loading chainstate, but I agree that duplicating the argument parsing just for this case isn’t worth it - removed, thanks

  15. in src/init.cpp:2284 in 69116ee97c outdated
    2287 | +        if (connOptions.onion_binds.empty()) {
    2288 | +            return InitError(_("The automatic Tor onion service requires a dedicated onion bind when -bind is set. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."));
    2289 | +        }
    2290 | +        if (std::ranges::any_of(connOptions.onion_binds, [](auto& b) { return b.IsBindAny(); })) {
    2291 | +            return InitError(_("The automatic Tor onion service cannot use a wildcard onion bind because incoming Tor connections would not be identified. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."));
    2292 | +        }
    


    vasild commented at 12:24 PM on October 1, 2026:

    This message is technically not correct. If wildcard address is used, incoming Tor connections will still be identified just fine. For example: -bind=1.2.3.4:8333 -bind=0.0.0.0:8334=onion - anything that arrives on port 8334 will be correctly identified as incoming Tor.

    The problem, however, is that 0.0.0.0:8334 in addition to being used for binding and classifying connections is also used to instruct the Tor daemon to forward incoming connections to it. And telling the Tor daemon to forward connections to 0.0.0.0:8334 is ill.

    So, maybe something like: "The automatic Tor onion service cannot use a wildcard onion bind because the Tor daemon wouldn't be able to forward incoming connections to us. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."

    Or just: "The automatic Tor onion service cannot use a wildcard onion bind. Use a specific address such as -bind=127.0.0.1:<port>=onion, or disable the service with -listenonion=0."


    l0rinc commented at 5:31 AM on October 7, 2026:

    Used your shorter version, thanks.

  16. in doc/release-notes-36170.md:4 in 69116ee97c
       0 | @@ -0,0 +1,8 @@
       1 | +P2P and network changes
       2 | +-----------------------
       3 | +
       4 | +Nodes configured with `-bind` but no specific `-bind=<addr>=onion` now refuse to start when `-listenonion` is enabled.
    


    vasild commented at 12:33 PM on October 1, 2026:
    Nodes configured with `-bind` but no specific `-bind=<addr:port>=onion` now refuse to start when `-listenonion` is enabled.
    
  17. in doc/release-notes-36170.md:6 in 69116ee97c outdated
       0 | @@ -0,0 +1,8 @@
       1 | +P2P and network changes
       2 | +-----------------------
       3 | +
       4 | +Nodes configured with `-bind` but no specific `-bind=<addr>=onion` now refuse to start when `-listenonion` is enabled.
       5 | +This includes nodes without Tor configured, since `-listenonion` is enabled by default when listening.
       6 | +Shared and wildcard binds cannot distinguish Tor-forwarded connections from direct connections, which can grant Tor peers unintended IP-based whitelist permissions.
    


    vasild commented at 12:35 PM on October 1, 2026:
    Shared binds cannot distinguish Tor-forwarded connections from direct connections, which can grant Tor peers unintended IP-based whitelist permissions.
    

    same reasoning as in the comment above, wildcard can distinguish.


    l0rinc commented at 5:32 AM on October 7, 2026:

    I kept "wildcard" here because the IPv4 and IPv6 checks described above both showed misclassification and retained whitelist permissions.


    vasild commented at 9:17 AM on October 19, 2026:

    Further clarification (thanks for double checking this after an offline chat):

    • Indeed shared binds cannot distinguish incoming Tor vs direct connections. E.g. if we bind on 1.2.3.4:8333 and accept incoming Tor and incoming direct connections on that address and port then we can't distinguish, obviously.

    • If we use a wildcard bind for Tor, e.g. -bind=0.0.0.0:8334=onion, then the problem is slightly different. I got this wrong initially, thanks for correcting me. The wildcard will bind on all addresses of the machine, e.g. 127.0.0.1:8334, 1.2.3.4:8334, 5.6.7.8:8334 and there will be no overlap between those and the direct connections 1.2.3.4:8333. So far so good, but when an incoming Tor connection arrives, we will then compare the address it arrived on e.g. 5.6.7.8:8334 to whatever was given to -bind which is 0.0.0.0:8334 and that will not match :bomb:. So the connection will be wrongly not considered as an incoming Tor connection. In theory, if we want to fix this:

    https://github.com/bitcoin/bitcoin/blob/6301d464f72d2752867c974e747f7a78b4f8322f/src/net.cpp#L1791

    then we would have to tweak that comparison to "if there is an entry in m_onion_bind that is a wildcard and the port matches to the port in addr_bind, then consider they are equal. I think that is unnecessary.

    • s/Tor-forwarded connections/incoming Tor connections/
  18. in doc/release-notes-36170.md:8 in 69116ee97c
       0 | @@ -0,0 +1,8 @@
       1 | +P2P and network changes
       2 | +-----------------------
       3 | +
       4 | +Nodes configured with `-bind` but no specific `-bind=<addr>=onion` now refuse to start when `-listenonion` is enabled.
       5 | +This includes nodes without Tor configured, since `-listenonion` is enabled by default when listening.
       6 | +Shared and wildcard binds cannot distinguish Tor-forwarded connections from direct connections, which can grant Tor peers unintended IP-based whitelist permissions.
       7 | +Nodes without `-bind`, including those using only `-whitebind`, continue to get the default onion target.
       8 | +Users should add a specific `-bind=127.0.0.1:<port>=onion` to accept incoming Tor connections, or set `-listenonion=0` to disable automatic onion service creation.
    


    vasild commented at 1:03 PM on October 1, 2026:

    The impression is that 127.0.0.1 must be used.

    Users should add a specific `-bind=<addr:port>=onion` to accept incoming Tor connections, or set `-listenonion=0` to disable automatic onion service creation.
    
  19. vasild commented at 1:03 PM on October 1, 2026: contributor

    Approach ACK 69116ee97cefa089f9eb6665918fb6c8b1ff62d4

  20. knst referenced this in commit 5f40d56f4d on Oct 5, 2026
  21. schildbach commented at 2:21 PM on October 6, 2026: contributor

    Keep in mind that when running in a container, it is considered best practise to bind to 0.0.0.0 / [::] rather than a specific IP. That is because most container engines (e.g. Docker) use dynamic IPs.

    The issue that 0.0.0.0 / [::] are unsuitable to pass via Tor control should imho be solved by a second configuration option, as suggested in #25094.

  22. PastaPastaPasta referenced this in commit d721befcf0 on Oct 6, 2026
  23. PastaPastaPasta referenced this in commit 4eb82f6c6d on Oct 7, 2026
  24. PastaPastaPasta referenced this in commit 0364ed626e on Oct 7, 2026
  25. l0rinc force-pushed on Oct 7, 2026
  26. l0rinc commented at 5:40 AM on October 7, 2026: contributor

    Addressed @vasild’s suggestions: reused the configured test arguments, removed the duplicate early check, shortened the errors, and clarified the release notes.

    The issue that 0.0.0.0 / [::] are unsuitable to pass via Tor control should imho be solved by a second configuration option

    I'd keep rejecting these configurations in this PR and handle that support separately. What do you think @vasild?

  27. vasild approved
  28. vasild commented at 9:21 AM on October 19, 2026: contributor

    ACK 5527295cb4b606cc372159cf040acbbe742b91ec

    The issue that 0.0.0.0 / [::] are unsuitable to pass via Tor control should imho be solved by a second configuration option

    IMO it would be an overkill to add one more configuration option to cover this. I think it should be possible to retrieve the IP address that docker assigned to the VM or instruct docker to assign a given one.

    <details> <summary>Show Signature</summary>

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA256
    
    ACK 5527295cb4b606cc372159cf040acbbe742b91ec
    
    > The issue that `0.0.0.0` / `[::]` are unsuitable to pass via Tor control should imho be solved by a second configuration option
    
    IMO it would be an overkill to add one more configuration option to cover this. I think it should be possible to retrieve the IP address that docker assigned to the VM or instruct docker to assign a given one.
    -----BEGIN PGP SIGNATURE-----
    
    iQRPBAEBCAA5FiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmrV4QIbFIAAAAAABAAO
    bWFudTIsMi41KzEuMTIsMiwzAAoJEFTfBvZLVcu/TN0f/R+EbsI+jQJdDAntyXfC
    wWpQ+eFu3j3AC7K/CoYrtVwhPUomeJMOJL8Q8RzZWE7XkdXU7Zu/ey9ezML3m3KD
    sKXdTc9YA/d6+MTGHZbReqksTzoX0sWS8ayXjyIpoSB/FtPE2mAvHnCLHXt+ZAtM
    DlZbZ1ocGXwxURECUGSwve92lvBnLv6ayS0lrmZPoMvq4kSgw1K9eR6Neqq0VTT6
    n2eVYc7Y2eFjCX4RDbXua9AYMoF+15KCXegABF0HzuCek929LaQeQMhrZXMn/3xK
    c47752l96wwRTgw3AigbtlwvT4jvlyD1s9jxhgTWRCX4uCWw55NImS5Yab5bsL6+
    YqfrsXOiWJ8hkqEcBnYP270iJV51wOOx3F+6a7laFo6fXkw+Sa1O/R0K6zldR/ud
    70aVQBVRrp0SxTyz5o4FeIqWEBXmkWTTRTZWU7BW0ZOwlCEMGDZqCb/oA9D8v5t3
    7KxdXsWg4rfJpQADr07GYTQO4JaouB+HY+ncpi3M7fXosO/okP2yu8zfyEn+N2zs
    TtE67DFJM28m8eCq2Fk1RX26Xjyd/EPpc4TT/WUpaEJrirwxoe6n4yENUC9fEfIW
    LNJfbV+n436P59fe7TQxhJDuFLN5N64pqViOPJcO6su2+QK5KnSPdjsMmvmFXSmQ
    uVcQgz91Lgh8NfrPTT04Hyj3mMsEkb8UH1qiNz+qCM/OHlWX9nUnT66aPG/b/uzh
    IlhWSBJwjDVxWe56H31LmVMFviSIpwZ1XU2J7leYUuFgr+P9wlGlT5BIInPhbuWp
    5fznSMTGSpglRH6UgOF5D4v/v9RpmKbmOcqkltjL0TD5xDrOzLXcaEJo7xb5lBTa
    rIjMxevrNx/2SFCMtNCtjoezRLexR+/MuDMZMHEAwXf5NmcMnpny5/co07+JHSX1
    24KrTq/3xGGiT+iuFU4ZjrY3TsUXpR84PA6nFpBWiVwl+Kkw7USJFt+6W2fc9tQ1
    IPgYo6Bho3HYUu/vXdgWCywaD18SZtdUshxi4FBx5XL6qwhv4QVJwzSfB628orDd
    Q8aP54a/pQrr+V3j14tHOJqYjIZgXNhyMASgoE0uU5jFDrY90yhIq/oz6siDOf1W
    D9VZ1HE9TRVlE2di1RrlmA2DM+gjjLPqFWnKXdPrr3StSa+6819Mgw5sffQO//wb
    mYO6mxhvXSGXmqMnbEGWKXaAk56NJL10HLL3t1xtQqBwYY1SdgF6T6DDr1bOh8Qm
    MO1DkHELCKZ+QLawGaKkPOIGBTtOlbauANxUd1uuJ9Hka30kjsj4+7+o4Lytpu6B
    O/CB0qlkOzeDIIjy9aCTd3lCvIz/4jg3D+7+LqjtRPPxVrw8UoYSA9jOLNV93vtQ
    9sw=
    =4syh
    -----END PGP SIGNATURE-----
    

    vasild's public key is on openpgp.org

    </details>

  29. DrahtBot requested review from winterrdog on Oct 19, 2026
  30. DrahtBot requested review from jeanpablojp on Oct 19, 2026
  31. jpk68 commented at 4:29 PM on October 21, 2026: contributor

    ACK 5527295cb4b606cc372159cf040acbbe742b91ec

  32. winterrdog commented at 8:14 PM on October 21, 2026: contributor

    tACK 5527295cb4b606cc372159cf040acbbe742b91ec

    successfully built & tested with clang++-19 on FreeBSD 15.0, targeting x86_64. changes LGTM


    since #34892 was closed in favour of this PR (https://github.com/bitcoin/bitcoin/pull/34892#issuecomment-5577081511), i think it makes sense to add a fixes [#33458](/bitcoin-bitcoin/33458/) in the the PR description so that the issue can be closed on merge because this PR actually resolves the issue

  33. knst referenced this in commit 92f2bfbc9d on Nov 2, 2026
  34. PastaPastaPasta referenced this in commit e81c51157f on Nov 2, 2026
  35. sedited commented at 2:54 PM on November 4, 2026: contributor

    Because -listenonion is enabled by default when listening, existing configurations with only a normal -bind must also be updated.

    I'm not sure about this approach. So any existing deployment that has a single bind, which I think is a common configuration, will now fail to start? That seems harsh to me. How about falling back to the default onion bind if no explicit one is given? Maybe I'm missing something, but wouldn't that match more closely with what would be expected to happen with a default on feature?

  36. vasild commented at 6:49 PM on November 4, 2026: contributor

    So any existing deployment that has a single bind, which I think is a common configuration

    Shouldn't be because that is flawed because then incoming IP and Tor cannot be distinguished. But I have no idea how widespread it is.

    will now fail to start?

    Right.

    That seems harsh to me.

    I agree, it is.

    Like a wake up call "fix your config!"

    How about falling back to the default onion bind if no explicit one is given? Maybe I'm missing something, but wouldn't that match more closely with what would be expected to happen with a default on feature?

    Note that then there is no way to disable the Tor bind. Right now we have:

    • by default both IP and Tor bind (if the user specifies no options)
    • if the user specifies only IP bind then we bind for IP only
    • if the user specifies both IP bind and Tor bind then we bind for both.

    I think that is logical and is a natural way to disable the Tor bind. By IP bind I mean -bind= and by Tor bind I mean -bind=...=onion.

    I agree it is harsh. I think it is acceptable though. But if others find it unacceptable, then it is unacceptable. What other ways might be, hmm...

  37. vasild commented at 5:33 AM on November 5, 2026: contributor

    So, the problem is if -listenonion=1 and only -bind= is used without -bind=...=onion. Then we tell the Tor daemon to forward incoming Tor connections to our normal bind and we cannot distinguish those from incoming IP connections.

    Some ideas, if the current approach seems unacceptable:

    • Log a startup warning and still end up in a state where IP and Tor incomings cannot be distinguished. A warning in the GUI as a pop up window will be noticed, but bitcoind users with only a warning in the log will probably miss it.

    • Brick only the Tor listening service. That is - allow start but refuse to create the Tor listening service and log a warning periodically, like:

    -listenonion is enabled but the Tor listening service was not created because there is no separate -bind=...=onion. To accept incoming Tor connections either remove the explicit -bind= which you have used (that will enable the default -bind=127.0.0.1:8334=onion) or add an explicit -bind=...=onion to your config.

    Might result the node operating in semi-degraded state for a long time before the user notices they have no incoming Tor connections and starts investigating. I still like more the refuse-to-start approach because it is obvious.

  38. vasild commented at 8:45 AM on November 5, 2026: contributor

    The root problem here is that there are two options that have to be set together: if -listenonion is set, then -bind=...=onion must also be set. And we are trying to handle the cases in which the later is not set. That is a bad interface.

    A good interface is impossible to misuse.

    So, what about another idea: the name of the option -listenonion is very confusing. I have always wished to do something about it ever since I grasped what it does. What it does is to automatically create the Tor service. It has nothing to do with listening, as in -bind. We might accept incoming Tor connections without it as well, if the Tor service is statically configured inside the Tor daemon, in torrc.

    So, what about replacing -listenonion with -bind=addr:port=onionauto? Note that in order to enable the auto Tor service creation, now one must specify a bind address and port. It is bundled together, impossible to misuse. Currently one can enable auto Tor service without specifying the listening address:port and that is a problem.

    old new
    -listenonion=0 don't specify -bind=addr:port=onionauto
    -listenonion=1 -bind=addr:port=onionauto

    The old default is as if -listenonion=1 -bind=0.0.0.0:8333 -bind=127.0.0.1:8334=onion were given. The new one will be as if -bind=0.0.0.0:8333 -bind=127.0.0.1:8334=onionauto were given.

    What about the problematic case where the user has only explicitly set -bind=addr:port and has inherited the default -listenonion=1 (and thus cannot distinguish incoming IP from Tor)? In the new variant with only an explicit -bind=addr:port and without an explicit -bind=addr:port=onionauto the Tor service will not be created.

  39. sedited commented at 11:25 AM on November 6, 2026: contributor

    Shouldn't be because that is flawed because then incoming IP and Tor cannot be distinguished. But I have no idea how widespread it is.

    Doing a cursory search, singular binds in general seem very common, it's even on the bitcoin wiki. I did find a couple of deployment configurations that don't include tor and set a single bind (1, 2).

    Brick only the Tor listening service. That is - allow start but refuse to create the Tor listening service and log a warning periodically, like:

    I don't see why we would necessarily have to brick it. Wouldn't using the current default bind if not onion bind is provided just continue working for most deployments?

  40. vasild commented at 2:21 PM on November 6, 2026: contributor

    Wouldn't using the current default bind if not onion bind is provided just continue working for most deployments?

    That is to ditch this PR? Then leave the problem it tries to resolve opened, from the OP:

    Problem: When the automatic onion service has no dedicated -bind=<addr>=onion, Tor forwards incoming connections to the first normal P2P bind. ... network classification is incorrect and Tor peers may inherit permissions granted to the Tor daemon's IP address.

    FWIW I considered this fine (to not be able to distinguish incoming Tor from IP), but I didn't think it would be widespread. It is a misconfiguration. And then AIs came and told us this this dangerous and I kind of agree to some extent...

  41. sedited commented at 12:43 PM on November 12, 2026: contributor

    That is to ditch this PR? Then leave the problem it tries to resolve opened, from the OP:

    I'm not suggesting doing nothing. Maybe I'm not quite following the actual problems, but what I'm suggesting is basically along the lines of adding -bind=127.0.0.1:<-port+1>=onion internally whenever a non-onion bind at port is detected in combination with -listenonion and no onion bind is given. Could also combine this with a warning that they should set their onion bind explicitly. I'm also not really sold whether to call this a misconfiguration, or a bug on our side.

  42. l0rinc commented at 5:52 PM on November 13, 2026: contributor

    Requested comments on IRC:

    RFC for #36170: Tor peers sharing a normal bind can inherit IP-based whitelist permissions. Should we add a default onion listener (see #36170 (comment)), refuse startup (current PR), or warn and skip service creation? Refusal affects non-Tor setups because -listenonion defaults on - adding a listener changes explicit bind behavior (and maybe risks port conflicts).

  43. hodlinator commented at 9:28 PM on November 13, 2026: contributor

    Wonder if we can navigate this issue through only failing during startup if: -listenonion AND -bind=IP AND -whitelist has been set. E.g., if this only is an issue when differing permissions are set for different IPs and adjusting permissions is not common, then this should catch the cases we worry about, while letting harmless & common cases continue.

    But maybe I'm missing some detail, I've just had a first look. (This idea was also communicated out of band with l0rinc).

  44. mzumsande commented at 3:04 PM on November 16, 2026: contributor

    I agree with sedited that this solution, which makes non-tor users of -bind change their setup by changing a tor-related config option set by default is not great. They haven't misconfigured anything, and it is not their fault that -listenonion is enabled by default if they don't use it or even know about it, so they should not be expected to turn it off.

    My favourite short-term solution would be to do what vasild mentioned ("Brick only the Tor listening service"). We could log a warning in torcontrol, but could still have tor outbounds with torcontrol. Having inbounds is, for the most part, a service to the network, and unlike on clearnet, inbound capacity isn't scarce on the tor network, so a couple of nodes not having inbounds anymore until they fix their config wouldn't be a major problem in my opinion.

    As a long-term solution, I would agree that replacing -listenonion makes sense, but that would require every tor user to change their config, so is not easily done.

    "-listenonion AND -bind=IP AND -whitelist has been set." would work, but it feels a little bit like a hack to me to disallow a certain combination of options that are not really related logically.

  45. refactor/test: prepare Tor bind handling and tests
    Prepare bind initialization and the mock-controller fixture to check explicit onion service targets and peer permissions without changing node behavior.
    
    Co-authored-by: HouseOfHufflepuff <ahrens@gmail.com>
    Co-authored-by: JP <jeanpablo.jp@hotmail.com>
    f745b12855
  46. test: characterize automatic Tor service creation
    Record that automatic service creation forwards to a shared P2P bind, that wildcard onion binds start normally, and that Tor control starts even when binding fails.
    Check outbound proxy discovery alongside incoming service creation so the fixes can preserve outgoing Tor connections.
    
    Co-authored-by: HouseOfHufflepuff <ahrens@gmail.com>
    Co-authored-by: JP <jeanpablo.jp@hotmail.com>
    fca97450f9
  47. init: start Tor control after binding listeners
    Start Tor control only after successful P2P binding so a failed bind cannot race service creation with a target owned by another process.
    52a24e59a0
  48. init: reject wildcard onion binds for automatic Tor
    Reject wildcard onion binds while automatic onion service creation is enabled because incoming connections report a concrete local address that does not match the configured wildcard.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    Co-authored-by: JP <jeanpablo.jp@hotmail.com>
    8189f2fe9a
  49. tor: skip automatic onion services without a dedicated bind
    With normal `-bind` options (but no `=onion` bind), retain the Tor controller for outbound proxy discovery but skip automatic incoming service creation, warning after authentication instead of forwarding incoming Tor connections to a normal P2P listener.
    
    This preserves explicit listener selection without refusing startup on non-Tor nodes, while retaining the default onion listener when no `-bind` is supplied.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    Co-authored-by: JP <jeanpablo.jp@hotmail.com>
    b8d7371d86
  50. doc: explain Tor startup without an onion bind ac8e9e3418
  51. l0rinc renamed this:
    net: require a dedicated bind for automatic Tor
    net: stop sharing P2P listeners with automatic Tor services
    on Nov 17, 2026
  52. l0rinc force-pushed on Nov 17, 2026
  53. l0rinc commented at 11:23 AM on November 17, 2026: contributor

    Thanks for the reviews and discussions!

    Rebased and pushed, a missing dedicated onion bind now disables only automatic incoming service creation instead of preventing startup, preserving the configured listeners and outbound proxy discovery. The controller warns after authentication so affected Tor users can add an explicit =onion bind to restore incoming connections.

    Tor control now waits for successful binding before requesting a service, and wildcard onion binds remain rejected with -listenonion enabled. To simplify review, refactors/characterization tests remain separate from behavior fixes (and their matching test updates), with documentation and comments last.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-20 15:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me