Skip to content

RPC: Connection limit and fail-ban protection (hardening pt.2) - #684

Open
SyntheticBird45 wants to merge 1 commit into
mainfrom
rpc-concurrency
Open

RPC: Connection limit and fail-ban protection (hardening pt.2)#684
SyntheticBird45 wants to merge 1 commit into
mainfrom
rpc-concurrency

Conversation

@SyntheticBird45

Copy link
Copy Markdown
Member

What

This PR follows and is based upon #675

It adds per-IP type simultaneous connection limits similar to monero-project/monero#9765. This PR extends this mitigation by adding a distinction between loopback addresses and private addresses, as well as enabling user to exclude specific IP addresses from any restriction if needed (main production case would be reverse proxies).

This PR also adds a short-term ban mechanism for IP addresses that repeatedly fails to be served by the hyper stack (axum erros are unaccounted). Said banned IP addresses are immediately dropped until they are unbanned.

@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
@SyntheticBird45
SyntheticBird45 force-pushed the rpc-concurrency branch 3 times, most recently from 7ee1e03 to 1296a55 Compare August 13, 2026 00:24
Comment thread binaries/cuprated/src/rpc/server.rs
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
Comment thread binaries/cuprated/src/rpc/server.rs
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
@SyntheticBird45
SyntheticBird45 requested review from Boog900 and redsh4de and removed request for redsh4de August 14, 2026 23:13
@github-actions github-actions Bot removed 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. labels Aug 14, 2026
@redsh4de

Copy link
Copy Markdown
Contributor

The counter never decays, so this is a 3s ban every 15th failure over the nodes whole uptime. Maybe worth bounding the strikes to a window of a minute or so?

@SyntheticBird45
SyntheticBird45 force-pushed the rpc-concurrency branch 5 times, most recently from 3a1c6c3 to 814eff4 Compare August 15, 2026 13:21
@SyntheticBird45

Copy link
Copy Markdown
Member Author

@redsh4de , I actually changed the semantic a little bit. There is now two DelayQueue, one for evicting the cache if the IP has stopped causing failure, and another one for if a banned IP's sentence is over.

There is no explicit list of what IP addresses are currently banned because looking up into DelayQueue is O(n) while in practice keeping the current HashMap O(1) (in most cases). So an IP address is effectively banned if its failure reached RPC_FAILURE_BAN_THRESHOLD. That is what is_ip_banned checks.

banned_ips has also been turned into a per_ip_failures HashMap since we don't need concurrency anymore.

Constants can be tweaked but at the moment, an IP address will keep its failure count for 5 second, this timer is reset everytime its increased, and erased when the IP is added to the unban queue.

@Boog900 Boog900 added this to the cuprated v0.1.0 preview 2 milestone Aug 20, 2026
@redsh4de

Copy link
Copy Markdown
Contributor

Needs rebase

Comment thread binaries/cuprated/src/rpc/server.rs Outdated
Comment thread binaries/cuprated/src/rpc/server.rs
@SyntheticBird45

Copy link
Copy Markdown
Member Author

Rebased

@SyntheticBird45
SyntheticBird45 force-pushed the rpc-concurrency branch 3 times, most recently from 3aa37e6 to 58d362a Compare September 4, 2026 21:28
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
Comment thread binaries/cuprated/src/rpc/server.rs
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
@SyntheticBird45
SyntheticBird45 force-pushed the rpc-concurrency branch 2 times, most recently from 09b58df to a8bc571 Compare September 5, 2026 10:43
Comment thread binaries/cuprated/src/rpc/server.rs Outdated
info!(
restricted,
address = %address,
address = %addr,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
address = %addr,
address = %addr,
port = %port,

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.

Co-authored-by: redsh4de <25299353+redsh4de@users.noreply.github.com>
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants