Repository navigation
fix(ratelimit): stop forwarded clients from dodging sign-in rate limits - #2364
Conversation
The auth-endpoint limiter keyed its per-client budgets on the address resolved from X-Forwarded-For or X-Real-IP. Every private range and loopback is a trusted proxy by default, so a client connecting from such an address could name a new client on each request and get a fresh login, setup, signup, invitation or device sign-in budget every time, on v1, v2 and the Jellyfin listener alike. A request whose client IP came from forwarding headers now also spends a budget keyed on the connection's own address, ten times the per-client one and shared by every client behind that proxy. Direct connections and network access ingress, whose plugin writes the header itself, spend the same budgets as before. clientip.PeerIP gives the peer in the same form as the resolved client IP so the two compare equal for a direct connection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The additional shared budget has no established merge-blocking defect. The documented possibility of temporary 429 responses for clients behind a busy proxy remains an expected tradeoff. Pre-merge checks |
|
Problem
Related issue: #1216
Validation tasks: none (the only passed case these budgets reach, #1196 C2, accepts one invitation, far below the new cap; #1217 C1, not run yet, covers rate throttling)
Sign-in rate limits could be dodged by sending a different
X-Forwarded-Foron every request. Thelogin,setup,signup,invitation, device sign-in and other auth budgets count per client IP, and the client IP comes from forwarding headers whenever the connection arrives from a trusted proxy. Every private range and loopback is trusted by default, so a LAN host, or any client whose connection reaches Silo through a container bridge, could name a new client on each request and start a fresh budget each time. The same limiter serves/api/v1,/api/v2and the Jellyfin listener, so all three were open to unlimited password guessing this way. On an unfixed server, 150 wrong-password sign-ins sent that way across the three surfaces were all answered 401, with no 429.Approach
When a request's client IP came from forwarding headers, it now also spends a second budget keyed on the connection's own address, which a client cannot forge. That budget is ten times the per-client one (for
login: 200 a minute, burst 100) and is shared by every client behind that proxy. A client that rotates the header stops there, and the users behind one real reverse proxy each keep their own per-client budget until together they reach ten times one client's allowance. The extra budget is checked after the per-client one, so a single client already over its own limit does not use up the budget the others behind its proxy share.Direct connections spend exactly what they did before, and so do requests through a network access provider such as the Tailscale plugin: its ingress token is checked first, and the plugin writes
X-Forwarded-Foritself, so the client cannot rotate it.This is a v1 change made during the bridge window as a critical fix, recorded in
docs/architecture/v1-scope.md. v2 and the Jellyfin listener change with it because they share the limiter.docs/auth-api.mdgains a short Sign-in rate limits section, and the Jellyfin and autoscan webhook docs point to it. Clients need no change: these routes already answered 429 withRetry-After.This touches only
AuthEndpointHandlerWithRejectBody, not the generic limiter that #2353 reorders. The two branches merge without conflicts.Validation
go build,gofmt,go vet,make lint-changed(0 issues), and the route inventory, local path and case collision checks pass. Inmake test-go,internal/ratelimitandinternal/clientippass. The other failures on the macOS test machine (TestAdminResourceCapabilitiesAndScope, two Jellyfin playback-info tests, three NFO lookup tests) fail the same way onmain.Evidence: https://evidence.siloserver.org/r/silo-server/auth-limit-peer-budget/
Evidence
No user-visible change. The steps, builds and trimmed results are on the evidence page linked under Validation.
Risks
login). Per-client budgets already behave this way on Redis.Checklist
AI Disclosure
81f4f69fffor remaining ways to get fresh budgets, legitimate users locked out behind proxies, memory/Redis parity, doc accuracy and test quality; no findings. An earlier multi-agent review of the diff led to keeping network access ingress off the shared budget, skipping peers that are not IP addresses, and doc corrections.🤖 Generated with Claude Code