Repository navigation
bugfix: send shortened IPv6 addresses to SOCKS5 proxies in full - #36675
instagibbs wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
There was a problem hiding this comment.
Workaround seems fine to do. But it's surprising the Tor daemon does not follow its own spec and format the IPv6 with brackets.
EDIT: had bot lookup the Tor sources and even the latest version still formats IPv6:port ambiguously, contrary to the spec. Arti does implement the spec correctly. May be worth upstreaming a bug report.
592d277 to
721e2f5
Compare
|
@darosior https://gitlab.torproject.org/tpo/core/tor/-/issues/32314 already known and closed. "Just use Arti" |
|
Concept ACK |
andrewtoth
left a comment
There was a problem hiding this comment.
ACK 721e2f5
Nice find. Tested with a small patch to only select IPV6 peers via private broadcast. Many SOCKS connection failures to addresses with :: on master, successfully connected to an address with :: with this patch.
This will also cause issues with anyone using the -proxy= with tor feature.
I see from a cursory analysis in bitnod.es that this would fail to connect to ~50% of known reachable ipv6 peers.
| assert_equal(cmd.port, 5443) | ||
| rv.append(cmd) | ||
| self.network_test(node, addr, network=NET_IPV6) | ||
|
|
There was a problem hiding this comment.
We could dedupe this with the above test.
diff --git a/test/functional/feature_proxy.py b/test/functional/feature_proxy.py
index 67274f9648..719737b340 100755
--- a/test/functional/feature_proxy.py
+++ b/test/functional/feature_proxy.py
@@ -164,15 +164,18 @@ class ProxyTest(BitcoinTestFramework):
rv.append(cmd)
self.network_test(node, addr, network=NET_IPV4)
- if self.have_ipv6:
- addr = "[1233:3432:2434:2343:3234:2345:6546:4534]:5443"
+ for host, expected in [
+ ("1233:3432:2434:2343:3234:2345:6546:4534", b"1233:3432:2434:2343:3234:2345:6546:4534"),
+ ("1233:3432::6546:4534", b"1233:3432:0:0:0:0:6546:4534"),
+ ]:
+ addr = f"[{host}]:5443"
self.log.debug(f"Test: outgoing IPv6 connection through node {node.index} for address {addr}")
node.addnode(addr, "onetry", v2transport=False)
cmd = proxies[1].queue.get()
assert isinstance(cmd, Socks5Command)
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
assert_equal(cmd.atyp, AddressType.DOMAINNAME)
- assert_equal(cmd.addr, b"1233:3432:2434:2343:3234:2345:6546:4534")
+ assert_equal(cmd.addr, expected)
assert_equal(cmd.port, 5443)
if not auth:
assert_equal(cmd.username, None)
@@ -180,18 +183,6 @@ class ProxyTest(BitcoinTestFramework):
rv.append(cmd)
self.network_test(node, addr, network=NET_IPV6)
- addr = "[1233:3432::6546:4534]:5443"
- self.log.debug(f"Test: outgoing IPv6 connection through node {node.index} for shortened address {addr}")
- node.addnode(addr, "onetry", v2transport=False)
- cmd = proxies[1].queue.get()
- assert isinstance(cmd, Socks5Command)
- # A shortened IPv6 address is sent with all eight groups, so that Tor does not read "<addr>:<port>" as one address
- assert_equal(cmd.atyp, AddressType.DOMAINNAME)
- assert_equal(cmd.addr, b"1233:3432:0:0:0:0:6546:4534")
- assert_equal(cmd.port, 5443)
- rv.append(cmd)
- self.network_test(node, addr, network=NET_IPV6)
-
if test_onion:
addr = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:8333"
self.log.debug(f"Test: outgoing onion connection through node {node.index} for address {addr}")
There was a problem hiding this comment.
applied but kept the have_ipv6 guard
Tor copies a SOCKS5 DOMAINNAME into its relay BEGIN cell as "<name>:<port>", and an exit parses "2001:db8::1:8333" as an IPv6 address with no port and closes the stream. Outbound connections through a Tor -proxy to IPv6 addresses that contain "::" therefore fail with "general failure". About a third of the IPv6 addresses the DNS seeds return have this form. Write such addresses with all eight groups. "<name>:<port>" is then not an IPv6 address, so the exit splits it at the last colon, and the name is still an address to proxies that resolve it with getaddrinfo, which brackets would break.
721e2f5 to
e8469d7
Compare
|
ACK e8469d7 |

Found while auditing #36628
Already known upstream issue with C-tor: https://gitlab.torproject.org/tpo/core/tor/-/issues/32314
With
-proxypointed at Tor, outbound connections to IPv6 peers whoseaddress contains an inner
::always fail with "general failure".Core sends every SOCKS5 destination as a DOMAINNAME, with IPv6 in its
compressed form. Tor copies the name into its relay BEGIN cell as
<name>:<port>, and the exit'stor_addr_port_splitfirst tries to parsethe whole string as an IPv6 address.
2001:db8::1:8333is a valid one,because the
::absorbs the port as an eighth group. The exit then sees noport and closes the stream. Addresses written with all eight groups, or
ending in
::, are unaffected: appending:portto them does not give avalid address.
About 20% of the IPv6 addresses in a gossip-filled addrman, and 29% of
current IPv6 DNS seed answers, have an inner
::. The failure is closed;there is no fallback to a direct connection.
Note that this also effects private broadcast by default.
This PR sends such addresses with all eight groups written out
(
2001:db8:0:0:0:0:0:1).<name>:<port>then has nine groups, so the exitsplits at the last colon. Other forms:
2001:db8::1(today)[2001:db8::1]Tested against tor 0.4.9.13: on mainnet, master could not reach four
seed-provided peers with inner-
::addresses (30 "general failure"); withthis change all four connected and completed the version handshake.
feature_proxy.pyand a newnetbase_testscase check the bytes sent.