Skip to content

http: Restore requirement of IPv4 bind success - #36187

Open
hodlinator wants to merge 6 commits into
bitcoin:masterfrom
hodlinator:2026/09/req_all_binds
Open

hodlinator wants to merge 6 commits into
bitcoin:masterfrom
hodlinator:2026/09/req_all_binds

Conversation

@hodlinator

@hodlinator hodlinator commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When bitcoind starts and the HTTP IPv4 listen address is occupied by another process, but the IPv6 address is available, the server fails open and generates a cookie file. When bitcoin-cli runs it picks up the cookie file and sends the credentials in plain text to the non-bitcoind process running on the default IPv4 port. An attacker can then use the credentials to commandeer bitcoind over IPv6.

Solution

Safe defaults:

  • When running with default settings, require that the IPv4 bind succeeds.
  • When -rpcbind is specified, require that all HTTP listen socket binds succeed (fail closed-behavior).

Node operators who only have IPv6 are now required to override -rpcbind and -rpcallowip to only specify the working interface and allowed subnet if they were not doing so already.

The problem of bitcoin-cli sending the credentials to what could possibly be the wrong process remains only in non-default setups.

History

40b556d from 2015 switched the HTTP server from Boost Asio to LibEvent, and binding switched from an attempt at dual-binding IPv4+v6 and falling back to IPv4-only (rpcserver.cpp / StartRPCThreads()), to binding IPv4 or IPv6 (httpserver.cpp / HTTPBindAddresses()). The current PR restores the prior behavior of IPv4 being mandatory.

#14968 from 2018 was an attempt to change the behavior to require all binds to succeed. But it ran into issues with poor IPv6 support on CI.

Severity

This credential exfiltration attack requires capability to launch processes on the bitcoind host. If we are on the same account we can already read the cookie credentials off disk. So it's only really interesting when an attacker is on a different user account on the same host.

@DrahtBot

DrahtBot commented Sep 7, 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
ACK l0rinc, janb84
Concept ACK sedited
Stale ACK winterrdog

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:

  • #37019 (http: free idle connection slots for waiting connections at the limit by optout21)
  • #36434 (http: support unix sockets by pinheadmz)
  • #36204 (http: disconnect clients that never finish a request by janb84)
  • #35355 (Use atomics for determining whether trace logging is enabled by ajtowns)
  • #34520 (refactor: Add [[nodiscard]] to functions returning bool+mutable ref by maflcko)

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.

@l0rinc

l0rinc commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Concept ACK, thanks for pushing the fix

@hodlinator
hodlinator marked this pull request as draft September 7, 2026 19:57
@hodlinator hodlinator changed the title http: Require all binds to succeed http: Require default IPv4 bind to succeed (again) Sep 7, 2026
@hodlinator

This comment was marked as resolved.

@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch from 054bcdc to 8e30cc9 Compare September 7, 2026 20:26
@hodlinator
hodlinator marked this pull request as ready for review September 8, 2026 06:49
@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch from 8e30cc9 to 64fd5ce Compare September 8, 2026 08:35

@janb84 janb84 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 64fd5ce

Looks good, some suggestion NITS.

NITl Commit message of c309e5f has a typo / grammar issue "and without this change that one would Mac CI would fail with:"

Comment thread test/functional/rpc_bind.py Resolved
Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved
@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch 2 times, most recently from bc9985a to 690a4b1 Compare September 8, 2026 20:06

@hodlinator hodlinator left a comment

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.

Latest push addresses all but 1 comment from #36187 (review)

Comment thread src/httpserver.cpp Resolved
@DrahtBot DrahtBot removed the CI failed label Sep 8, 2026
@sedited

sedited commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

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

concept ACK

this makes sense since bitcoin-cli defaults to IPv4, so bitcoind should have a corresponding IPv4 listener, already working by default as well

Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved
@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch from 690a4b1 to 05de7be Compare September 11, 2026 11:10

@hodlinator hodlinator left a comment

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.

Latest push avoids stringly typing endpoints_seen and addresses points from #36187 (review).

Comment thread src/httpserver.cpp Resolved
@hodlinator

Copy link
Copy Markdown
Contributor Author

Updated PR description, primarily the History-section.

@hodlinator hodlinator changed the title http: Require default IPv4 bind to succeed (again) http: Restore requirement of IPv4 bind success Sep 21, 2026
@sedited
sedited requested review from janb84, l0rinc and winterrdog and removed request for winterrdog November 4, 2026 12:36
@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch from 05de7be to 1e57675 Compare November 9, 2026 11:25

@hodlinator hodlinator left a comment

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.

Pushed 1e57675 to address latest round of review.

Comment thread src/httpserver.cpp Outdated
Comment on lines +235 to +236
endpoints.push_back({.address = "::1", .port = http_port, .required = false});
endpoints.push_back({.address = "127.0.0.1", .port = http_port, .required = 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.

re #36187 (comment):

I prefer maintaining the same order as on master.

Comment thread src/httpserver.cpp Resolved

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

t ACK 1e57675

As per description, this PR closes a real credential leak. Checked, verified and tested.

Thanks for taking the lookup suggestion!

LGTM !

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

tested ACK 1e57675

successfully built and tested with clang++-20 on Debian, targeting x86_64

@l0rinc l0rinc 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'll review this in more detail a bit later, left a few low-effort suggestions in the meantime...

Comment thread src/httpserver.cpp Resolved
Comment thread test/functional/rpc_bind.py Resolved
Comment thread test/functional/rpc_bind.py Resolved
Comment thread test/functional/rpc_bind.py Resolved
Comment thread src/httpserver.cpp Resolved
@DrahtBot
DrahtBot requested a review from l0rinc November 9, 2026 21:46
@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch from 1e57675 to a8e7faa Compare November 11, 2026 15:43

@hodlinator hodlinator left a comment

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.

Pushed new version based on l0rinc's initial feedback, sorry for invalidating the 2 ACKs.

Comment thread src/httpserver.cpp Resolved
Comment thread test/functional/rpc_bind.py Resolved
Comment thread test/functional/rpc_bind.py Resolved
@hodlinator

Copy link
Copy Markdown
Contributor Author

Removed AI Disclaimer from PR desc as it could be taken as avoidance of responsibility. Credits for finding the credential exfiltration vulnerability and the initial broad strokes solution still go in part to LLMs.

Comment thread src/httpserver.cpp Resolved

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

Thanks for taking my earlier suggestions! I went over the change more thoroughly now and left a few nits and cleanups. The reason I'm not acking yet is that the new deduplication drops IPv6 binds that differ only in their scope.

Comment thread test/functional/rpc_bind.py Resolved
Comment thread test/functional/rpc_bind.py Resolved
Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved
l0rinc and others added 3 commits November 13, 2026 15:34
When the IPv4 RPC address is already owned, the server starts on its remaining IPv6 listener for both default and explicit bind configurations. bitcoin-cli then sends the generated cookie to the other process on its default IPv4 destination.

Record the partial startup and exact captured Authorization credential for the following fail-closed fix.
The next commit requires all binds to succeed, and without this change that one would fail on Mac CI with:
[InitHTTPServer] [warning] Binding RPC on address 127.1.1.1:19036 failed: Unable to bind to 127.1.1.1:19036 on this computer (bind returned error Can't assign requested address (49))

The options in this test are there to verify log censorship of sensitive data and bind-addresses were made non-sensitive in bitcoin#26829 / b9d5674. That commit added the missing -rpcallowip option to actually make -rpcbind not be ignored any longer. That commit added 127.0.0.1 in addition to the already existing 127.1.1.1, probably because the latter would fail by itself.
@hodlinator
hodlinator force-pushed the 2026/09/req_all_binds branch from a8e7faa to 44bcdbd Compare November 13, 2026 14:53

@hodlinator hodlinator left a comment

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.

Latest push addresses #36187 (comment) and #36187 (review) + adds anonymous namespace to make BindAddress fully local to httpserver.cpp.

Comment thread src/httpserver.cpp Resolved
Comment thread test/functional/rpc_bind.py Resolved
Comment thread src/httpserver.cpp Resolved
Comment thread src/httpserver.cpp Resolved

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

ACK 44bcdbd

If you need to touch this again, consider using a smaller reproducer in the characterization commit (showing that startup succeeds despite the occupied IPv4 port), with the full credential-capture proof in a collapsible section of the PR description as an optional demo. That would avoid removing all that code we just introduced in the earlier commit.

Comment thread src/httpserver.cpp Resolved
hodlinator and others added 3 commits November 14, 2026 10:50
Allows us to catch fail earlier and have simpler code in a later commit where binds are required to succeed.

Co-authored-by: janb84 <[email protected]>
Co-authored-by: winterrdog <[email protected]>
While the search is quadratic, we don't expect many local bind addresses.
When any RPC bind succeeds, initialization ignores every other endpoint failure. A process that already owns the default IPv4 port can therefore receive bitcoin-cli credentials while the node continues on IPv6.

Switch to safe defaults through only making the default IPv6 address optional, requiring all others. Hosts intentionally providing only an IPv6 interface must use -rpcbind to set that endpoint explicitly.

This carries the fail-closed policy from bitcoin#14968 now that the in-tree socket implementation reports each bind result.

Co-authored-by: laanwj <[email protected]>
Co-authored-by: Lőrinc <[email protected]>
@l0rinc

l0rinc commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

reACK 061eb6f

Just the explanatory comment and the shared allow_names variable and the lambda capture cleanup since my last ack.

@fanquake

Copy link
Copy Markdown
Member

cc @pinheadmz

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

re ACK 061eb6f

There are some behavioral changes in startup, maybe consider adding a release-note (Ralph suggested the same, but cryptic in his reasoning).
The change that could use a release note is for Ipv6 only hosts, a host or jail without 127.0.0.1 / ipv4 used to start (on master) on ::1 alone. The same functionality now needs -rpcbind=[::1] -rpcallowip=::1 other wise the node will error out.

with (socket.create_server(('127.0.0.1', self.defaultport)),
self.nodes[0].assert_debug_log([f"Binding RPC on required address '127.0.0.1:{self.defaultport}' failed:"])):
self.nodes[0].assert_start_raises_init_error(extra_args, 'Error: Unable to start HTTP server. See debug log for details.')

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, non-block. Adding something like the test below will fix 2 of the gaps in test as reported by corecheck.

Suggested change
def run_optional_ipv6_bind_test(self):
self.log.info('Check that the node starts on IPv4 when the default IPv6 RPC address is already owned')
self.nodes[0].rpchost = None
with socket.create_server(('::1', self.defaultport), family=socket.AF_INET6):
with self.nodes[0].assert_debug_log([f"Binding RPC on optional address '[::1]:{self.defaultport}' failed:"]):
self.start_node(0, ['-disablewallet', '-nolisten'])
assert_equal(set(get_bind_addrs(self.nodes[0].process.pid)), {(addr_to_hex('127.0.0.1'), self.defaultport)})
self.stop_node(0)
def run_unbindable_bind_test(self):
self.log.info('Check that startup fails when an explicit RPC address cannot be bound, even if others succeed')
# 192.0.2.1 (TEST-NET-1, RFC 5737) is not assigned to a local interface,
# so bind() fails with EADDRNOTAVAIL rather than EADDRINUSE.
extra_args = ['-disablewallet', '-nolisten', '-rpcallowip=127.0.0.1', '-rpcbind=127.0.0.1', '-rpcbind=192.0.2.1']
with self.nodes[0].assert_debug_log([
f"Binding RPC on address '127.0.0.1:{self.defaultport}'",
f"Binding RPC on required address '192.0.2.1:{self.defaultport}' failed:",
]):
self.nodes[0].assert_start_raises_init_error(extra_args, 'Error: Unable to start HTTP server. See debug log for details.')
def run_unresolvable_bind_test(self):
self.log.info('Check that startup fails when an explicit RPC address is not numeric, even if others are')
extra_args = ['-disablewallet', '-nolisten', '-rpcallowip=127.0.0.1', '-rpcbind=127.0.0.1', '-rpcbind=localhost']
with self.nodes[0].assert_debug_log(
[f"Could not lookup RPC bind address 'localhost' port {self.defaultport} (only numeric addresses are allowed)."],
unexpected_msgs=["Binding RPC on address"], # fails before any bind is attempted
):
self.nodes[0].assert_start_raises_init_error(extra_args, 'Error: Unable to start HTTP server. See debug log for details.')

@hodlinator

Copy link
Copy Markdown
Contributor Author

Thanks for the review @janb84! As stated out-of-band, starting to write the release notes you suggested motivated me to look into being less harsh on IPv6-only hosts.

Upon failure to bind the IPv4 loopback port, we could create an IPv4 socket and try to bind it to a random ephemeral port. If that also fails, we could assume that we don't have an IPv4 stack at all and let the IPv6-only bind be sufficient. I'll need some more time to investigate this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants