Rate Limiting
This page explains how ProxyAuth's rate limiter actually decides what counts as "the same client," and how that combines with the requests_per_second/burst settings from config.json. See the config.json Reference for the basic configuration syntax — this page is about the mechanism behind it.
Where rate limiting applies
| Route(s) | Governed by |
|---|---|
/auth, /adm/auth/totp/get |
ratelimit_auth |
| Everything else (proxied traffic) | ratelimit_proxy |
/adm/revoke, /adm/logs, /adm/stats*, /adm/auth/totp/reset |
Not rate-limited — protected only by the admin token |
/auth and /adm/auth/totp/get share the same rate-limit configuration (ratelimit_auth) because both are password-guessing surfaces — OTP enrollment/provisioning is just as sensitive to brute-forcing as login itself.
The rate-limit key: what counts as "one client"
This is the part that isn't obvious from config.json alone. Each request's rate-limit bucket is keyed by:
"<request path>:<identity>"
Where <identity> is resolved, in order:
- A valid
Authorization: Bearer <token>— if present and it decodes to a real user, that username is the identity. - Otherwise, a valid
session_tokencookie — same idea, only checked ifsession_cookieis enabled inconfig.json. - Otherwise, the client's IP address.
And the IP address used in step 3 (and as a fallback throughout) is resolved the same trusted-proxy-aware way as the rest of the application — see trust_proxy_forward_for in the config.json Reference. X-Forwarded-For/X-Real-Ip are only honored from peers you've explicitly listed as trusted; otherwise the actual TCP peer address is used, so a client can't spoof a fresh rate-limit bucket by sending a fake forwarding header.
Practical effect: an authenticated user gets their own rate-limit bucket per route, tied to their username — not their IP. This means a user working from an office NAT (sharing an IP with colleagues) doesn't get throttled by others' traffic once they're logged in, but an anonymous/pre-login client (most importantly, someone hammering /auth itself, where there's no valid session yet to identify them by) is limited by IP.
Burst vs sustained rate
Each rate limit has two numbers:
| Setting | Meaning |
|---|---|
requests_per_second |
The sustained rate a given key is allowed, long-term. |
burst |
Extra capacity available on top of the sustained rate, consumed and refilled over time (a token-bucket, not a fixed window) — lets a client briefly exceed the sustained rate (e.g. a page load firing several requests at once) without being throttled, as long as they're not sustaining it. |
requests_per_second: 0 disables the limit entirely for that config block (proxy or auth) — every request passes through unthrottled.
What happens when the limit is hit
429 Too Many Requests, with:
- A
Retry-Afterheader, in seconds, telling the client how long until it can try again. - A JSON body:
{"code":429, "error": "TooManyRequests", "message": "Too Many Requests", "after": 3}
Every 429 response is also logged with the client IP, method, path, and User-Agent — useful for spotting brute-force attempts against /auth even before you'd notice them any other way.
Tuning guidance
ratelimit_authshould be strict. This is your brute-force defense on login and OTP enrollment — a lowrequests_per_second(a handful per minute is often plenty for a real user occasionally mistyping a password) with a smallburstis appropriate. Since the key includes IP for unauthenticated requests, legitimate users behind a shared IP (NAT, corporate network) can still be affected by each other's failed attempts here — that's an intentional trade-off between usability and brute-force resistance.ratelimit_proxyis your general traffic shaping. Since authenticated users are keyed by username (not IP) once logged in, this can usually be more generous without one user's traffic starving another's.- Neither limit protects
/adm/*routes. If you're worried about brute-forcingtoken_adminitself, that's currently a matter of choosing a long, high-entropy admin token — there's no rate limit backstopping it. See Admin Routes Reference.
See also
- config.json Reference —
ratelimit_auth/ratelimit_proxysyntax, andtrust_proxy_forward_for. - Admin Routes Reference — the routes rate limiting does not cover.
📖 Wiki Home · 💻 Source Code · 🐛 Report an Issue · 📜 License
Found an error or something outdated on this page? Open an issue or submit a PR against the wiki repository.