mirror of
https://github.com/truespar/sentio.git
synced 2026-11-17 16:17:37 +00:00
rate_limit_middleware was never wired into the router, and it keyed only on the AuthContext extension - which no middleware ever inserted, since authentication happens in the handler extractor. So nothing was rate limited at all. The router now layers three stages on authenticated routes: an IP-keyed pre-auth limiter (120 req/min per address) that meters token guessing and abuse of public endpoints, then auth middleware that resolves the bearer token once and publishes the context as a request extension (handlers reuse it instead of repeating the DB lookup), and finally the per-tenant limiter reading that context. Health, docs, and tracking endpoints stay outside the auth layer. Client IPs come from the socket peer; when the peer is a configured trusted proxy (SERVER__API_TRUSTED_PROXIES), the X-Forwarded-For origin is used instead. A direct client cannot spoof the header past the limiter.