api: a per-client rate limit on the HTTP API, with trusted proxies for X-Forwarded-For

600 /api/ requests a minute per client address (--requests-per-minute), 429 with Retry-After; static UI files and the node's own machine are exempt. The real client behind a reverse proxy is read from X-Forwarded-For only when the connection comes from a --trusted-proxy, taking the last entry that is not itself a trusted proxy. k8s: TRUSTED_PROXY in config.env (the private ranges) is passed as --trusted-proxy.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-19 00:35:21 +01:00
co-authored by Claude Sonnet 5.5
parent 5ac02360c4
commit 3799faddcf
10 changed files with 296 additions and 17 deletions
+14 -1
View File
@@ -719,8 +719,21 @@ Findings (see "What is left" in SPECS.md for the open ones):
Behind a Kubernetes service the real source address is only visible with
`externalTrafficPolicy: Local` (the base manifest has it; the nodeport
overlay uses `Cluster`, which hides it, so the limit does nothing there).
- **HTTP API:** at most 600 `/api/` requests a minute per client address
(`--requests-per-minute`, -1 for no limit), answered with 429 and
`Retry-After`; the UI's static files are not counted, and requests from the
node's own machine are exempt so the owner is never locked out. On top of
that, posting messages and tips keep their own, much lower limit (30 a
minute). Behind a reverse proxy the client is read from `X-Forwarded-For`
only when the connection comes from a `--trusted-proxy` (address or
network, repeatable), and then it is the last entry that is not itself a
trusted proxy, so what a client writes itself is never believed. Without a
trusted proxy every client behind the proxy shares one allowance; the
manifest sets `TRUSTED_PROXY` to the private ranges for that reason. A
request carrying forwarding headers is never treated as local, so a proxy
on the node's machine does not exempt its clients.
Bans are per node and not shared (a shared ban would let one node get
honest ones banned); the HTTP API still has no limits.
honest ones banned).
3. **The DHT is only as good as its servers.** Only publicly reachable nodes
serve it. With every seed gone, a newcomer whose remembered peers are all in
another region found nobody (0 of 114 listings), and one that remembers no