Repository navigation
fix(rpc): serve only safe RPC methods on public nodes, trust CF-Connecting-IP only from Cloudflare ranges, check the RPC config in CI - #11
Merged
Conversation
…cting-IP only from Cloudflare ranges, check the RPC config in CI
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.
Summary
The public RPC nodes answered unsafe RPC methods (
author_rotateKeys,author_removeExtrinsic,system_addReservedPeer,offchain_localStorageSet,system_peers, …). The binary forces--rpc-methods Unsafeso remote relayers can reach the ISMP queries, so the--rpc-methods Safein the compose files had no effect, and Caddy does not filter methods.Node endpoints (testnet and mainnet
rpc)--rpc-port/--rpc-external/--rpc-methods/--rpc-max-connectionsare replaced by two--experimental-rpc-endpoints, each withmethods=safe. An endpoint's ownmethods=applies regardless of the forced global setting:RPC_BIND:RPC_PORT(9944), 3500 connections, no per-connection limit (Caddy pools many users onto few upstream connections).127.0.0.1:RPC_WS_PORT(9945), 1500 connections,rate-limitofRPC_WS_RATE_LIMITcalls/min per socket (default 1200 = 20/s). Caddy can only count WS connections, not the calls inside them.RPC_BINDmakes the HTTP bind explicit:0.0.0.0(firewalled), because the relayer reads rpc-1 at10.0.0.10:9944over the private network;127.0.0.1.ismp_*) have no unsafe check, so the relayer is unaffected.Caddy
@viaCf,@wsViaCf) also require a source IP in Cloudflare's published ranges (cloudflare_edgesnippet). Before, a client reaching the origin directly could send a freshCF-Connecting-IPper request and land in a new rate-limit bucket each time.Docs and CI
docs/rpc-node.md: the real limits (HTTP 500 req / 10 s per IP; WS 30 new connections / 60 s, plus 1200 calls/min per socket at the node) and the safe-methods-only behaviour.tests/test_rpc_config.py(stdlibunittest, no Docker), run by the Lint workflow. It checks:methods=safeand none of the legacy RPC flags;max_conns_per_host× imports stays below each endpoint'smax-connections;CF-Connecting-IPmatcher is guarded by the Cloudflare ranges.Verification
system_peersandauthor_rotateKeys→-32601 RPC call is unsafe to be called externally;ismp_queryStateProofstill answers.caddy-ratelimitimage:localhost:9944/localhost:9945.CF-Connecting-IPfrom a non-Cloudflare source (limit lowered to 3 for the test):tests/test_rpc_config.py: passes on this branch; fails onmain(unsafe methods, missing endpoints, unguarded CF matchers).docker compose configpass for both networks.Deploy
The new variables have defaults, so existing
.envfiles keep working.