mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
WIP: rpc: invalid credentials can occupy every HTTP worker #36200
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!36200
Loading…
Reference in a new issue
No description provided.
Delete branch "2026/09/http_auth_sleep"
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
RPC clients are able to easily DoS the HTTP server due to an obligatory worker thread sleep upon authentication failure.
Solution
Remove the sleep.
While this allows the guess rate to increase, it also fixes the DoS vector and reduces production code.
History
fe98cf8dc5from 2010 introduced RPC authentication along with the sleep. At that point the password authentication was timing-sensitive depending on the length, so the credentials could have been brute-forced. A sleep was added to help mitigate these timing attacks (and also reduce the guess rate).The same author then introduced
TimingResistantEqual()in42656ea2e5/ https://github.com/bitcoin/bitcoin/pull/2886 in 2013 to solve the timing attack once and for all (https://github.com/bitcoin/bitcoin/issues/2838 / CVE-2013-4165). That made the sleep only serve to reduce the guess rate.Severity
Low since the attack requires RPC clients to be granted network access to a node.
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.
A summary of reviews will appear here.
Conflicts
No conflicts as of last run.
This sleep also slows online password guessing, so I'm not sure I agree that it was made redundant by the addition of
TimingResistantEqual().Removing it might be reasonable to avoid tying up shared HTTP workers, but I think the description should acknowledge the increased guessing rate.
This attack requires network access to the RPC listener, not valid RPC credentials (if that's what you meant by "grated access to a node").
Good points!
Improved the PR desc.
It's not obvious to me that removing this DoS vector is more important than reducing the guess rate you point out. Both of these only occur when we have a malicious attacker who already has network access (on localhost or via
-rpcallowip).Moved to draft.
Another approach that has been mentioned out-of-band is rate-limiting connection attempts from the same IPs. IP source addresses can be spoofed though, so the attacker could make it look as if it was a well-behaving client which failed authentication and induce DoS that way.
Maybe a better approach would be to just expand the existing comment with these trade-offs. What do you think?
Yeah I think the DoS vector identified here is cheaper/easier to hit (and more annoying), so I'd be in favour of patching that up as you propose. I mainly wanted to point out that I didn't think the sleep was totally superfluous.
Perhaps we can leave repeated guessing up to external tools like fail2ban or similar (and document, if wanted)? i think it could be handled pretty trivially with something like:
and
Then no action required on our side :)
Hm.. wondering if we should add fail2ban docs or not. Maybe it just makes the RPC/HTTP ports seem more like something which we expect to be open to the public internet.
An alternative approach to removing the 250ms sleep is to spawn a dedicated "Slow RPC reply" thread which we could hand off the socket and work to upon authentication failure. That way we don't block any HTTP workers but still keep the guess-rate down. Not sure the added complexity would justify itself though.
Edit: Addendum - the source IP (range?) we hand off the sleep for should not be allowed to attempt another authentication before the 250ms timeout though... otherwise we don't keep the guess-rate down.
This is in draft since I've got mixed feelings about the approach. Do we want to avoid occupying every HTTP worker at the price of vastly increasing the guess-rate?
Rejected alternative
Been mulling over a more complex approach of:
Upon authentication failure, free up the worker, but queue a "reply"-job with a deadline which keeps enqueuing itself until it reaches the deadline and then fires off the
HTTP_UNAUTHORIZEDreply. That way we allow other jobs while still keeping the guess-rate down.That would solve the thread workers limit but we would probably still hit the max connections limit and end up being DoS:ed that way though.
Alternative under consideration
Is a responsive HTTP server more important than keeping RPC passwords secret?
Does the password authentication without the sleep take enough time that we could claim user error for choosing short passwords?
If the password is stored as plaintext, we could examine it inside
InitRPCAuthentication()and at least warn if it seems too short/simple. That would make it more acceptable to remove the sleep.Guarding against longer but flawed passwords would probably involve something like https://github.com/dropbox/zxcvbn. But adding such a dependency or dropping in an implementation seems like something that might not pay for itself if used only for RPC passwords. Maybe there's a case to be made for including it if we use it for new wallet passphrases as well. We probably should probably help users by at least warning against defective wallet passphrases. There was an attempt to add such checks for wallet passphrases in #17950.
Maybe it would be passable for now to:
Base:
60afa0b8d71ff0959eac27fe73fadafe72b70cceHead:
15ced063da3fc623c89cb0faea40fc4cfc0c3271Findings
Suggestions
Reduce timing sensitivity in the worker regression test (test/functional/interface_http.py:533, head)
The test starts timing only after detecting the warning, which the old handler emits before sleeping, and after constructing the valid connection. With the old code, time spent before the timer starts can consume much of the 250 ms delay; with the new code, scheduling or request latency can exceed the 200 ms cutoff. Consider pre-establishing clients and queuing multiple failed requests before a valid request, then verifying their order through the worker queue. The old behavior would produce a larger cumulative delay, allowing a less sensitive cutoff.
Design and approach
Clarify whether RPC must retain a failed-authentication throttle (src/httprpc.cpp:221, base)
Removing the 250 ms wait removes a fixed cost from each failed credential attempt; CheckUserAuthorized compares credentials but does not meter attempts. A client admitted by the HTTP allowlist can therefore make failed attempts without that per-attempt delay, subject to other server costs. Should RPC preserve an online-guessing limit with a bounded mechanism that does not occupy an HTTP worker, or is removing this throttle an intentional security tradeoff? The checkout establishes the behavior change, but not the resulting practical guess rate or the project's required limit.
Concept and approach. Removing the sleep improves responsiveness by freeing HTTP workers, but the approach leaves the intended online-guessing protection unclear. Clarify the required protection and, if one is needed, use a bounded mechanism that does not occupy workers (PR #2886).
Review coverage was incomplete. adversarial: The remainder of MaybeDispatchRequestToWorker and HTTPRequest::WriteReply in src/httpserver.cpp was not inspected; queue and reply-backpressure behavior could affect the resource impact of faster authentication rejection. adversarial: The warning logger's throttling and I/O synchronization were not inspected; these could bound or amplify failed-authentication log load after the worker sleep is removed. adversarial_glm: Output failed validation: invalid review output verifier: The linked historical PR #2886 discussion could not be retrieved, so its account of the timing-attack history was not independently verified. The current code findings are based on the checked-out implementation.
Full review report
Reading the IRC discussion in https://github.com/bitcoin/bitcoin/pull/17950#issuecomment-583081308, it seems like we ended up with text in a markdown file instead: #28974
I'm concerned that most users who would need to read that will not unless it is also put into the GUI.