How do you secure a publicly exposed RPC node?
The core answer is simple: a publicly exposed RPC node should never be left open to the entire internet without protection. You secure it by combining network-level access control, request filtering, rate limiting, and constant monitoring. If you run a node that accepts RPC requests from anyone, you are inviting abuse, data theft, and potential node crashes.
Understand the Risk
A public RPC node lets anyone send calls to your Ethereum client. Malicious actors can:
- Drain your node’s bandwidth and compute resources with heavy queries like
eth_getLogsover wide block ranges. - Use your node as a free relay for spam transactions or contract interactions they do not want traced back to them.
- Attempt to exploit known vulnerabilities in your client software, especially if you are running an outdated version.
- In extreme cases, if your node is also a validator or has a funded account, expose that account’s private key through misconfigured endpoints.
The goal is not to block all traffic - you presumably want some external users - but to restrict what they can do and how much they can do.
Step 1: Restrict Access by IP or Network
Do not bind your RPC endpoint to 0.0.0.0 (all interfaces) unless you have a firewall in front of it. Bind it to 127.0.0.1 if only local applications need it. If external users must reach it, bind to a specific internal IP and let your firewall or reverse proxy handle external traffic.
Use a firewall rule to whitelist only the IP ranges that need access. For example, if your users are all in a single office or cloud VPC, allow only that CIDR block. If you serve a broader audience, consider a cloud load balancer or a service like Cloudflare’s Spectrum, which can filter traffic before it reaches your node.
Step 2: Use a Reverse Proxy for Request Filtering
A reverse proxy (Nginx, Caddy, HAProxy) sits between the internet and your node. It lets you:
- Terminate TLS (HTTPS) so traffic is encrypted.
- Block known malicious IPs using geo-blocking or threat intelligence feeds.
- Inspect and reject certain RPC methods. For example, you can block
eth_sendRawTransactionif you only want read-only access, or blockdebug_*andadmin_*methods entirely. - Enforce request size limits to prevent oversized payloads.
A minimal Nginx configuration might look like:
location / {
proxy_pass http://127.0.0.1:8545;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 30s;
if ($request_method !~ ^(POST|OPTIONS)$ ) {
return 405;
}
}
But you should also add a block list for dangerous methods. Many reverse proxies support Lua scripting or third-party modules for this.
Step 3: enable rate limiting
Without rate limiting, a single user can hammer your node with thousands of requests per second, degrading service for everyone. Configure rate limits per IP address. A common starting point is 100 requests per second per IP, but you may need to adjust based on your node’s capacity and typical usage patterns.
Your reverse proxy can handle this. For Nginx, the limit_req module works well. You can also use dedicated rate-limiting middleware like nginx-http-ratelimit or a cloud service.
Step 4: configure CORS properly
If your RPC is consumed from web applications, set Access-Control-Allow-Origin to a specific domain, not *. A wildcard origin allows any website to make requests from a user’s browser, which can lead to cross-site request forgery or data exfiltration.
In your reverse proxy:
add_header Access-Control-Allow-Origin "https://yourdapp.com";
add_header Access-Control-Allow-Methods "POST, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type";
Step 5: Run Your Node with Minimal Privileges
Do not run your Ethereum client as root. Create a dedicated user with no login shell. Restrict the node’s file system access to its data directory only. Use systemd or Docker with user namespaces to further isolate it.
Keep your client software updated. Subscribe to security advisories for Geth, Erigon, Nethermind, or whichever client you run. Patches for critical vulnerabilities are released regularly. Apply them promptly.
Step 6: Monitor for Abuse
Set up logging of all RPC requests. Monitor for:
- Spikes in request volume from a single IP.
- Repeated calls to expensive methods like
eth_getLogswith large block ranges. - Attempts to access admin or debug endpoints.
- Requests from unexpected geographic regions.
Use tools like Prometheus and Grafana to track request counts, latency, and error rates. Alert when any metric exceeds a threshold you define.
When you should not expose a public RPC
If you are running a node for personal use (e.g., for your own dapp or wallet), do not expose it publicly at all. Use a private RPC behind a firewall or VPN. The convenience of having it open is rarely worth the risk.
If you must serve many users, consider using a commercial RPC provider instead. They handle security, scaling, and abuse mitigation for you. Hosting your own public RPC is a significant operational responsibility.
The Bottom Line
Securing a public RPC node is about layering defenses: network access control, a reverse proxy for filtering and rate limiting, proper CORS configuration, minimal system privileges, and active monitoring. None of these steps is optional if you care about keeping your node stable and your resources intact. If you cannot commit to maintaining all of them, do not expose the node publicly.
Not financial advice. starname.me publishes market data and general information about digital assets. Crypto assets are volatile and you can lose everything you put in. Nothing here is a recommendation to buy, sell or hold, and we make no price predictions.
Prices are sourced from third parties and may be delayed or wrong. Verify anything you intend to act on against a primary source.