Skip to content

RPC: Block endpoints semaphore access (hardening pt.4) - #686

Open
SyntheticBird45 wants to merge 4 commits into
mainfrom
rpc-hardening-block-semaphore
Open

RPC: Block endpoints semaphore access (hardening pt.4)#686
SyntheticBird45 wants to merge 4 commits into
mainfrom
rpc-hardening-block-semaphore

Conversation

@SyntheticBird45

Copy link
Copy Markdown
Member

This PR follows and is based upon #685

It adds a new limiting layer called BlockSemaphoreLimitLayer that 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 a 503 Service unavailable response with a Retry-After header.

Original idea from @Boog900

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
SyntheticBird45 force-pushed the rpc-hardening-block-semaphore branch from 7c77e21 to e6d3b22 Compare August 13, 2026 01:20
@github-actions github-actions Bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Area: Changes to a root workspace file or general repo file. A-binaries Area: Related to binaries. labels Aug 13, 2026
@Boog900 Boog900 added this to the cuprated v0.1.0 preview 2 milestone Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-binaries Area: Related to binaries. A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Area: Changes to a root workspace file or general repo file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants