Skip to content

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
nol4lej merged 1 commit into
mainfrom
fix/rpc-safe-methods
Oct 12, 2026
Merged

nol4lej merged 1 commit into
mainfrom
fix/rpc-safe-methods

Conversation

@nol4lej

@nol4lej nol4lej commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

The public RPC nodes answered unsafe RPC methods (author_rotateKeys, author_removeExtrinsic, system_addReservedPeer, offchain_localStorageSet, system_peers, …). The binary forces --rpc-methods Unsafe so remote relayers can reach the ISMP queries, so the --rpc-methods Safe in 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-connections are replaced by two --experimental-rpc-endpoints, each with methods=safe. An endpoint's own methods= applies regardless of the forced global setting:
    • HTTP on RPC_BIND:RPC_PORT (9944), 3500 connections, no per-connection limit (Caddy pools many users onto few upstream connections).
    • WebSocket on 127.0.0.1:RPC_WS_PORT (9945), 1500 connections, rate-limit of RPC_WS_RATE_LIMIT calls/min per socket (default 1200 = 20/s). Caddy can only count WS connections, not the calls inside them.
  • RPC_BIND makes the HTTP bind explicit:
    • testnet keeps 0.0.0.0 (firewalled), because the relayer reads rpc-1 at 10.0.0.10:9944 over the private network;
    • mainnet defaults to 127.0.0.1.
  • ISMP queries (ismp_*) have no unsafe check, so the relayer is unaffected.

Caddy

  • WSS goes to the node's rate-limited WebSocket endpoint; HTTPS stays on 9944.
  • The Cloudflare branches (@viaCf, @wsViaCf) also require a source IP in Cloudflare's published ranges (cloudflare_edge snippet). Before, a client reaching the origin directly could send a fresh CF-Connecting-IP per request and land in a new rate-limit bucket each time.
  • The ranges are a static copy, like the ufw allow-list: update both when Cloudflare changes them.

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 (stdlib unittest, no Docker), run by the Lint workflow. It checks:
    • every public endpoint has methods=safe and none of the legacy RPC flags;
    • the WS endpoint is loopback and rate-limited;
    • Caddy's max_conns_per_host × imports stays below each endpoint's max-connections;
    • every CF-Connecting-IP matcher is guarded by the Cloudflare ranges.

Verification

  • Local dev node 0.4.0 with the new endpoints:
    • system_peers and author_rotateKeys → -32601 RPC call is unsafe to be called externally;
    • ismp_queryStateProof still answers.
  • Caddyfile adapted with the real caddy-ratelimit image:
    • 22 ranges in each Cloudflare matcher;
    • caps unchanged (500+500 WS, 400+400 HTTP);
    • upstreams localhost:9944 / localhost:9945.
  • Forged, rotating CF-Connecting-IP from a non-Cloudflare source (limit lowered to 3 for the test):
    • old config 200 ×6;
    • new config 200 ×3, then 429.
  • tests/test_rpc_config.py: passes on this branch; fails on main (unsafe methods, missing endpoints, unguarded CF matchers).
  • pre-commit (prettier, yamllint) and docker compose config pass for both networks.

Deploy

The new variables have defaults, so existing .env files keep working.

git pull
docker compose up -d --force-recreate orbinum-rpc-node caddy
curl -s -H 'content-type: application/json' \
  -d '{"id":1,"jsonrpc":"2.0","method":"system_peers","params":[]}' https://rpc-1.testnet.orbinum.io
# expect: {"error":{"code":-32601,"message":"RPC call is unsafe to be called externally"}}

…cting-IP only from Cloudflare ranges, check the RPC config in CI
@nol4lej
nol4lej merged commit 797ae82 into main Oct 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant