JWT rate limiting strategies
November 11, 2026 · 13 min read
JWT authentication proves who is calling; rate limiting decides how often they may call. Tokens complicate throttling because one IP (NAT) carries many users and one user rotates tokens. Effective strategies layer IP bounds with per-sub quotas after JWT validation.
Goals: fairness, cost control, abuse prevention
Limit login and token endpoints aggressively to slow credential stuffing. Limit expensive API routes per tenant. Return 429 with Retry-After and problem+json bodies so clients backoff.
Per IP and anonymous limits
Before JWT validation, apply IP-based limits to auth endpoints and public routes. Use sliding windows or token buckets at CDN edge. Beware carrier-grade NAT - pair IP limits with account limits after auth.
Per subject, client_id, and jti
- Extract
subafter verification for per-user quotas. - Machine clients: throttle by
client_idor OAuth client assertion subject. - Optional per-
jticaps to detect token replay floods (short windows).
Gateway and service mesh limits
API gateways can validate JWT once, attach sub to request context, and enforce Redis-backed counters. Inner services trust gateway headers only on mTLS internal networks. Document limit headers (X-RateLimit-Remaining) in OpenAPI.
Abuse scenarios with JWT
Stolen tokens bypass IP limits if the attacker distributes globally - short exp and refresh rotation matter more than IP alone. Brute force of introspection endpoints needs separate limits. Decode abuse tokens in staging with JWT decoder to see which claim to key on.
FAQ
- Rate limit before or after JWT verify?
- Cheap IP limits before; per-user limits after successful verify so invalid tokens cannot exhaust user buckets.
- Does JWT size affect limits?
- Large headers hit proxy limits before rate limits - keep claims lean.
- How to limit refresh endpoint?
- Strict per-IP and per-refresh-token or per-session counters; lock account on anomaly.
Related: JWT in microservices · JWT best practices · JWT attack types · Common API auth problems