Skip to content

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

Draft
hodlinator wants to merge 1 commit into
bitcoin:masterfrom
hodlinator:2026/09/http_auth_sleep
Draft

hodlinator wants to merge 1 commit into
bitcoin:masterfrom
hodlinator:2026/09/http_auth_sleep

Conversation

@hodlinator

@hodlinator hodlinator commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

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

fe98cf8 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 42656ea / #2886 in 2013 to solve the timing attack once and for all (#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.

A low-medium service-availability issue lets an admitted HTTP client hold each shared worker for 250 ms per invalid Basic credential, filling the waiting queue and delaying or rejecting authenticated RPC and REST work.

Remove the worker-thread sleep while preserving authentication, warning logs, challenge responses, and timing-resistant comparison.
@DrahtBot

DrahtBot commented Sep 9, 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.
A summary of reviews will appear here.

Conflicts

No conflicts as of last run.

Comment thread src/httprpc.cpp
/* Deter brute-forcing
If this results in a DoS the user really
shouldn't have their RPC port exposed. */
UninterruptibleSleep(std::chrono::milliseconds{250});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hodlinator Sep 10, 2026 •

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.

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
hodlinator marked this pull request as draft September 9, 2026 11:21
@hodlinator

Copy link
Copy Markdown
Contributor Author

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:

@hodlinator

Copy link
Copy Markdown
Contributor Author

Reading the IRC discussion in #17950 (comment), 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 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.

4 participants