RPC: Block endpoints semaphore access (hardening pt.4) - #686
Open
SyntheticBird45 wants to merge 4 commits into
Open
RPC: Block endpoints semaphore access (hardening pt.4)#686SyntheticBird45 wants to merge 4 commits into
SyntheticBird45 wants to merge 4 commits into
Conversation
This commit adds a new struct called RpcServer that is used to accept new TCP connections and serving them through hyper and axum. This replaces axum::serve. A new async IO timeout wrapper called StreamTimeout is added to each new connections. The read_timeout and send_timeout configuration keys are used to set the duration for which, if elapsed, the client is disconnected if no bytes has been received or sent respectively.
Add a per-IP connection limit layer to the RPC servers. Every type (public, private or loopback) of IP addresses have a configurable maximum amount of simultaneous connection. The node also have a configurable total maximum amount of simultaneous connections. Whenever one limit is exceeded, the connection is dropped. Add a short-ban mechanism against IP addresses which fails to be served more than 15 times. This is a protection against malicious clients spamming garbage instead of parseable HTTP requests.
…Axum Adds a new ratelimit.rs file containing an Axum middleware for rate limiting requests based on a response size and processing time budget. Clients that have exceeded either of these two budgets are not served and are responded with a `429 Too many requests` error response. The budget is refilled with an income. Both the maximum budgets and incomes are configurable. This commit also modifies RpcCacheLimit::remove_connection to return a boolean indicating whether the last connection for this IP has been terminated. This is used to start an eviction task that will delete the IP entry from the rate limiting state after a period of time (or be cancelled if the IP reconnected in the mean time). Assisted-by: Boog900 <boog900@tutanota.com>
Add a limit middleware based on semaphore for limiting the amount of block endpoint requests being processed simultaneously. Any additional request will be put on hold for a maximum period of time. If the request has not been processed before that delay, the client gets a `503 Service unavailable` response with a `Retry-After` header indicating the next time to request again.
SyntheticBird45
force-pushed
the
rpc-hardening-block-semaphore
branch
from
August 13, 2026 01:20
7c77e21 to
e6d3b22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR follows and is based upon #685
It adds a new limiting layer called
BlockSemaphoreLimitLayerthat limit the maximum amount of block endpoints (get_blocks.bin,get_blocks, etc...) requests being processed simultaneously. Any additional request is put on hold for a configurable period of time. If that delay is exceeded, the request is dropped and the clients receives a503 Service unavailableresponse with aRetry-Afterheader.Original idea from @Boog900