WIP: rpc: invalid credentials can occupy every HTTP worker #36200

Draft
hodlinator wants to merge 1 commit from 2026/09/http_auth_sleep into master AGit
hodlinator commented 2026-09-09 08:32:17 +00:00 (Migrated from github.com)

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

fe98cf8dc5 from 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() in 42656ea2e5 / 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.

#### 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 fe98cf8dc5066368b78e9ce208118c3532598dd2 from 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()` in 42656ea2e552b027e174fdceab7348ffcb8245c4 / 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.
DrahtBot commented 2026-09-09 08:32:25 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36200 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36200.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36200#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
willcl-ark (Migrated from github.com) reviewed 2026-09-09 11:06:08 +00:00
willcl-ark (Migrated from github.com) commented 2026-09-09 11:05:42 +00:00

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.

Severity

Low since the attack requires RPC clients to be granted access to a node.

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").

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. > Severity > > Low since the attack requires RPC clients to be granted access to a node. 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").
hodlinator (Migrated from github.com) reviewed 2026-09-09 11:29:44 +00:00
hodlinator (Migrated from github.com) commented 2026-09-09 11:29:44 +00:00

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?

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?
willcl-ark (Migrated from github.com) reviewed 2026-09-10 07:36:56 +00:00
willcl-ark (Migrated from github.com) commented 2026-09-10 07:36:56 +00:00

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:

# /etc/fail2ban/filter.d/bitcoind-rpc.conf
# ~ Bitcoin Core debug.log format
[Definition]
failregex = ^\s*\[warning\] ThreadRPCServer incorrect password attempt from <ADDR>:\d+\s*$
ignoreregex =

and

# /etc/fail2ban/jail.d/bitcoind-rpc.local
[bitcoind-rpc]
enabled = true
filter = bitcoind-rpc
backend = polling
logpath = /var/lib/bitcoind/debug.log
usedns = no
port = 8332
protocol = tcp
maxretry = 5
findtime = 10m
bantime = 1h
ignoreip = 127.0.0.0/8 ::1
action = nftables[type=multiport, name=bitcoind-rpc, port="8332", protocol=tcp]

Then no action required on our side :)

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: ``` # /etc/fail2ban/filter.d/bitcoind-rpc.conf # ~ Bitcoin Core debug.log format [Definition] failregex = ^\s*\[warning\] ThreadRPCServer incorrect password attempt from <ADDR>:\d+\s*$ ignoreregex = ``` and ``` # /etc/fail2ban/jail.d/bitcoind-rpc.local [bitcoind-rpc] enabled = true filter = bitcoind-rpc backend = polling logpath = /var/lib/bitcoind/debug.log usedns = no port = 8332 protocol = tcp maxretry = 5 findtime = 10m bantime = 1h ignoreip = 127.0.0.0/8 ::1 action = nftables[type=multiport, name=bitcoind-rpc, port="8332", protocol=tcp] ``` Then no action required on our side :)
hodlinator (Migrated from github.com) reviewed 2026-09-10 11:16:11 +00:00
hodlinator (Migrated from github.com) commented 2026-09-10 11:16:11 +00:00

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.

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.*
hodlinator commented 2026-10-12 09:08:31 +00:00 (Migrated from github.com)

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_UNAUTHORIZED reply. 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:

  • Remove the sleep
  • Only check the RPC password length, and warn if too short
  • Add a comment referencing #17950 in the hopes that if it is ever implemented for wallets, it can be used for RPC as well
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_UNAUTHORIZED` reply. 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: * Remove the sleep * Only check the RPC password *length*, and warn if too short * Add a comment referencing #17950 in the hopes that if it is ever implemented for wallets, it can be used for RPC as well
First-time contributor

Base: 60afa0b8d71ff0959eac27fe73fadafe72b70cce
Head: 15ced063da3fc623c89cb0faea40fc4cfc0c3271

Findings

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

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `60afa0b8d71ff0959eac27fe73fadafe72b70cce` Head: `15ced063da3fc623c89cb0faea40fc4cfc0c3271` ##### Findings **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](https://github.com/bitcoin/bitcoin/pull/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](<https://review.fish.foo/traces/36200-15ced063da3fc623c89cb0faea40fc4cfc0c3271-697-1.html>)
hodlinator commented 2026-10-12 09:33:55 +00:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36200
No description provided.