mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
http: Restore requirement of IPv4 bind success #36187
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36187
Loading…
Reference in a new issue
No description provided.
Delete branch "2026/09/req_all_binds"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
-rpcbindis specified, require that all HTTP listen socket binds succeed (fail closed-behavior).Node operators who only have IPv6 are now required to override
-rpcbindand-rpcallowipto 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
40b556d374from 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.
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.
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:
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.
Concept ACK, thanks for pushing the fix
For some reason thought that we weren't enabling the HTTP subsystem by default. Going to re-work the code slightly. Put in draft.
Concept ACK 64fd5cef0c938d3d1e7f69d6be2f255b6eafc1e2
Looks good, some suggestion NITS.
NITl Commit message of c309e5fb73 has a typo / grammar issue "and without this change that one would Mac CI would fail with:"
NIT: I would keep the style of the 2 lines the same (helps the OCD people)
non blocking, micro nit: Currently even the required entry/bindings failure only logs as a LogWarning. Is that the correct level for something that aborts startup ?
NIT: Leftover assert on started, Line 121 asserts that started is false so started cannot be true at this point.
Latest push addresses all but 1 comment from https://github.com/bitcoin/bitcoin/pull/36187#pullrequestreview-5139772278
Will do if others agree, holding off for now.
Concept ACK
concept ACK
one of the "others" has arrived 😁
anyway, i agree with @janb84
when i first looked at the code, i thought there might be a subtle
reason for using one over the other, but later on i realised they do
the same thing. so i think sticking to the same pattern makes sense.
whether you use
emplace_back()orpush_back()is up to you, as longas there is some symmetry
from the PR description:
can we make the IPv6-only case a bit more actionable in the error message ?
with the new defaults, an IPv6-only host will fail because the required
127.0.0.1bind will never succeed, but the user may not know that they need to override-rpcbindto use only their IPv6 address. mayhaps the error could point them towards-rpcbindrather than just reporting that a required endpoint failedi was thinking of sth like (feel free to put a spin to it):
Latest push avoids stringly typing
endpoints_seenand addresses points from https://github.com/bitcoin/bitcoin/pull/36187#pullrequestreview-5172841125.Good point. Default behavior for IPv6-only hosts should at least be to get an informative error message.
Updated PR description, primarily the History-section.
Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🔵 Suggestion · RPC bind startup changes lack upgrade guidance
Configurations that previously started with partial RPC bind success can now fail initialization, but the PR adds no release note and the help text does not explain the new requirements.
Location:
src/httpserver.cpp:1387(head).🔵 Suggestion · IPv6 bind failure policies lack regression coverage
Both new failure cases occupy only IPv4, so they do not distinguish optional default IPv6 from required explicit IPv6.
Location:
test/functional/rpc_bind.py:63(head).🔵 Suggestion · IPv4-only runs skip the default occupied-port check
The new default occupied-IPv4 case runs only through the IPv6-gated branch, leaving IPv4-only hosts without this regression check.
Location:
test/functional/rpc_bind.py:175(head).Review coverage was incomplete.
Reviewed:
061eb6f43458· Review report · Previous reportspermalink
ACK
05de7be9d7This PR will solve the problem stated in the PR description. Some observations/ NITS:
"Node runners who only have IPv6 are now required to override -rpcbind to only specify the working interface if they were not doing so already."
Isn't it more correct to say that: "Node runners who only have IPv6 are now required to override -rpcbind and -rpcallowip to only specify the working interface if they were not doing so already." Without -rpcallowip=::1 it will still fail.
The code will solve a ipv4 squatter situation, but not the case when there is a ipv6 sqatter and
localhostis used for bitcoin-cli , 'bitcoin-cli -rpcconnect=localhost` tries [::1] before 127.0.0.1 . Not a blocker because 127.0.0.1 is explicitly used but just an observation.Found a non-blocking NIT in the code, see below.
NIT: current
BindAddresskeeps the address as a string, andInitHTTPServerparses it later with Lookup. This "late" lookup has the consequence that an invalid-rpcbindvalue is only detected inside the bind loop. Resulting that possible earlier endpoints may already be listening, andStopListening()has to undo them.I think we can do this lookup (with fAllowLookup=false) sooner, as pure numeric parse without DNS (So it is safe to call it in
GetBindAddresses) and store it typed. This is the same way the lookup is done in the bind loop.This has the benefit that any invalid -rpcbind address fails before any socket is opened, equal to the
portlogic. And, to me, failing fast without the "risk" of opening sockets, is the better security posture.patch
not a blocker, just wanted to understand why IPv4 does not come first in the vector, given that it is the required endpoint for successful startup ?
GetBindAddresses()can sometimes return an empty vector. I think we could handle that here and return early+1, i think it makes sense to fail-fast
went ahead and extended your patch a little by making
InitHTTPServer()fail fast (as well) when a required endpoint fails to bind. this removes the need forbind_success,required_failure, and the failure-handling helper. we just handle the failure where it happens and return immediately.i think this will make the control flow simpler and easier to follow, with less state to keep track of. plus, it also avoids attempting further binds when we already know startup cannot succeed
extended patch
WDYT ?
Pushed
1e5767518ato address latest round of review.thread https://github.com/bitcoin/bitcoin/pull/36187#discussion_r4481607697:
Good ideas! Added as refactor-commit in the middle. Nice to get rid of the
on_failure-lambda.re https://github.com/bitcoin/bitcoin/pull/36187#discussion_r4486162809:
I prefer maintaining the same order as on master.
t ACK
1e5767518aAs per description, this PR closes a real credential leak. Checked, verified and tested.
Thanks for taking the lookup suggestion!
LGTM !
i had put IPv4 first mostly because
bitcoin-clidefaults to127.0.0.1. so, if that endpoint cannot be bound, we already know that the default client cannot safely connect tobitcoindwith this ordering, we can abort before even attempting IPv6, rather than starting an RPC server that
bitcoin-clicannot reliably reach.that was my reasoning
tested ACK
1e5767518asuccessfully built and tested with
clang++-20on Debian, targetingx86_64I'll review this in more detail a bit later, left a few low-effort suggestions in the meantime...
Could we deduplicate while building
endpoints? It's quadratic, but likely a lot faster because we don't expect many element. Then the bind loop can use the collected list directly without keeping a separate set.Deduplicate while collecting RPC endpoints
My understanding is that without
-rpcallowip, the suggested-rpcbindis ignored and an IPv6-only host gets the same startup failure again.Include both required options in the IPv4 failure hint
I'd keep the credential capture in the characterization commit and use
assert_start_raises_init_error()for the permanent regression test.Use the existing startup-error helper
If we move this to the end of the
elsebranch in_run_loopback_tests(), it would remove the extra check and leaverun_test()unchanged.Run partial-bind cases after the existing loopback tests
nit: move a repeated endpoint to the existing multi-port case and drop this separate restart.
Combine duplicate and multi-port coverage
Pushed new version based on l0rinc's initial feedback, sorry for invalidating the 2 ACKs.
re https://github.com/bitcoin/bitcoin/pull/36187#discussion_r4518281015:
Was thinking deduplicating on the receiver side was somehow better defensive programming, but within the same file it's not that important, and we indeed do not expect many bind-addresses. Taken.
re https://github.com/bitcoin/bitcoin/pull/36187#discussion_r4518305687:
Flipping the
assert_equal()s felt clear, but agree that it's good to keep the test simpler going forward. Taken with little modification. Simplified the initial characterization commit as well to make the diff smaller.re https://github.com/bitcoin/bitcoin/pull/36187#discussion_r4518289854:
Taken, although I opted for repeating
127.0.0.1:32172so one can more easily compare.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.
(edited)
CServiceequality ignores the IPv6 scope ID, so the new dedupe drops-rpcbind=[fe80::1%2]after-rpcbind=[fe80::1%1]without a warning, while master attempts both binds.ToStringAddrPort()comparison should probably fix it.Bind one link-local address on two interfaces
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.
This refactor already changes the endpoint type, so it seems like the natural place to introduce
BindAddress, with just theCServicefor now. The fail-closed commit would then only need to addrequired, and the endpoint types wouldn't change twice.Introduce the wrapper before adding bind requirements
nit: with the lookup in the
ifinitializer,addronly lives in the branch that uses it, and the happy path comes first (similarly to a try/catch) - the same in the parsing refactor would also drop itscontinue.Scope the lookup result to its branch
nit: the initializers and ranges already have unambiguous types, so
autoworks forendpoints, both ports, the lookup result and the-rpcbindloop element. Reading the port withGetArg<uint16_t>also removes thestatic_cast, andCheckHostPortOptions()already rejects an out-of-range-rpcportat startup.Deduce types supplied by initializers and ranges
nit: some of these messages quote the bind address and some don't. Single quotes throughout would make them consistent, and the lookup error would no longer need escaped double quotes.
Use single quotes around RPC bind addresses
Since
requiredalready picks the branch, each branch can log its own message, which drops the temporarymsgand itsrequired ? "required" : "optional"ternary.Inline required and optional failure messages
I don't think
reuse_port=Trueis needed:create_server()already setsSO_REUSEADDRon POSIX, and both occupied-port cases pass without it on macOS and Linux. The characterization commit has the same flag.nit: since this statement changes anyway, a parenthesized
withgets rid of the weird trailing backslash.Reserve the IPv4 port without SO_REUSEPORT
nit:
assert_equal(started, True)can never fail, since a failingstart_node()already leaves the function before it. Droppingstartedand the initialcredential_captured = Falsechanges nothing, and the TODO fits on thestart_node()line itself.Remove dead startup state from the characterization
Latest push addresses https://github.com/bitcoin/bitcoin/pull/36187#discussion_r4543016954 and https://github.com/bitcoin/bitcoin/pull/36187#pullrequestreview-5871193906 + adds anonymous namespace to make
BindAddressfully local to httpserver.cpp.Thanks for finding this! Added the test and fixed in latest push, but I had to expose an accessor for
CNetAddr::m_scope_id.Good point regarding
GetArg<uint16_t>()! Kept slightly more explicit local type info in the other cases for now.There's no clear winner to me, but guess avoiding an extra branch is nice and
msgwas just used in 2 places.True (https://docs.python.org/3/library/socket.html#socket.create_server), removed in latest push.
ACK
44bcdbd1c6If 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.
This looked fishy: why compare internal
CServicestate separately after==? Extending the shared operator here looks tempting, but it would also change peer connection deduplication, inbound onion listener matching and AddrMan key lookup, so we definitely should not do it in this PR.And if we do that, ordering and hashing should also be adjusted in a separate follow-up.
The explicit scope check seems fine here, but maybe we could add a comment explaining why it is needed, something like:
Agreed, I independently realized this while thinking it over again yesterday. Pushed a variation of the comment.
Also realized the "Don't allow hostname lookups when binding to local interfaces."-comment above applies to other
Lookup()calls so extractedallow_names-variable and hoisted it up above.reACK
061eb6f434Just the explanatory comment and the shared
allow_namesvariable and the lambda capture cleanup since my last ack.Yes, it comes down to keeping the diffs clear vs avoiding unnecessary work in the case that IPv6 binding succeeds but then IPv4 binding fails. I guess optimizing for the end state after the PR is also an aspect in your favor. I'll swap the order if I need to re-touch, unless others are against the swap.
cc @pinheadmz
re ACK
061eb6f434There 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
::1alone. The same functionality now needs-rpcbind=[::1] -rpcallowip=::1other wise the node will error out.Nit, non-block. Adding something like the test below will fix 2 of the gaps in test as reported by corecheck.
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.