Track 08 · Lesson 17 of 20Attacks and defenses
- 01What HTTPS protects
- 02The same-origin policy
- 03CORS
- 04Security headers
- 05Cookies done right
- 06Cross-site scripting (XSS)
- 07Content Security Policy
- 08Cross-site request forgery (CSRF)
- 09Clickjacking
- 10Unsafe URLs and open redirects
- 11Prompt injection
- 12SQL and command injection
- 13Prototype pollution, CRLF and SVG
- 14Server-side request forgery (SSRF)
- 15Remote code execution and denial of service
- 16Spoofed headers
- 17Rate limiting
- 18Cache poisoning
- 19The OWASP Top 10
- 20The attack lab
Track 08 · Attacks and defenses
Rate limiting
Lesson 17 of 20· 6 min
Rate limiting allows each client only so many requests per window, like five login attempts a minute. The key that defines “each client” is everything: if the attacker can change it, the limit vanishes.
Forty password guesses
Change the attacker and the limiter’s key
✕ reached the password check · ✓ refused with 429 · – account locked
Guesses that reached the password check
0
Keys in the limiter’s memory
0
Choosing the key#
- The trusted client IP, from the hop you control (the last lesson), stops one machine.
- Per account, on top of per IP, stops many machines guessing one password. Lock or slow down after a few failures, tell the owner, and offer a reset rather than a permanent lockout.
- Never a value the client typed, like the first
X-Forwarded-Forentry.
Limiters have memory too#
An in-memory limiter keeps a counter per key. If expired keys are never swept, an attacker who invents a new key per request fills your server’s memory. Sweep every window, cap the number of keys, and use a shared store like Redis when you run more than one instance.
Not just logins#
Anything expensive for you and cheap for the caller deserves a limit: password reset emails, one-time-code checks, link previews, search, exports and AI calls.
In a code review
MediumAppRate limiter keyed on a spoofable value
Fix: Key on the trusted client IP or user ID; sweep every window; cap the map; prefer a shared store (Redis) when running several instances.
0 of 2 checked
Check yourself