Rate limiting is usually added after an incident, applied per IP address, and set to a number somebody guessed. It then blocks a legitimate corporate office sharing one address while an attacker rotating through residential proxies passes straight through.
Pick the right dimension
Per-IP limiting is the default and the weakest. Attackers distribute across large proxy pools; legitimate users share addresses behind corporate NAT and mobile carrier networks. You get both failure modes at once.
Limit on what the attacker cannot cheaply vary:
- Per target account. Limit failed logins against a username regardless of source. A password-spraying attack hitting one account from a hundred addresses is invisible per-IP and obvious here.
- Per authenticated identity. After login, limit by user or API key. This is the strongest dimension because the attacker must burn an account to exceed it.
- Per endpoint sensitivity. Password reset, login, registration, search and export need different limits from reading a static page.
- Globally, as a backstop. A cap on total failed authentication attempts across the application catches distributed attacks that stay under every individual threshold.
Combine them. Per-IP catches the unsophisticated, per-account catches spraying, global catches everything else.
The endpoints that need it most
Authentication. Failed logins per account and globally. Prefer progressive delay over hard lockout, because lockout on username alone hands an attacker a denial-of-service tool against your customers.
Password reset and registration. Abused to enumerate which addresses are registered and to send mail from your domain at someone else's expense. Limit per address and per recipient.
Anything that sends a message. Email, SMS, push. Each request costs real money and reputation, and these are the first endpoints abused when found.
Search and list endpoints. Expensive to serve and the standard vector for bulk scraping of your data.
Export and report generation. One request can consume substantial resources, so a very low limit is appropriate.
Anything taking an identifier. Even with correct authorisation, an endpoint that returns different responses for valid and invalid identifiers allows enumeration of what exists.
Respond in proportion
Blocking is not the only option and often not the best one.
- Delay. Adding increasing latency makes automation uneconomic while remaining imperceptible to a human.
- Challenge. Present a challenge after a threshold rather than refusing outright.
- Degrade. Serve cached or reduced results to suspected automation.
- Block, with a clear
429and aRetry-Afterheader so legitimate clients back off correctly instead of retrying immediately and making it worse.
Make responses uniform
Rate limiting does not help if the responses themselves leak information. A login that says "no such user" for one address and "wrong password" for another is an enumeration oracle regardless of any limit.
Return the same message and, as far as practical, the same timing for both cases. Response time differences are measurable and are routinely used when the message is identical.
Enforce it where it cannot be skipped
Limits applied in client-side code or in a single service are bypassed by calling a different entry point. Enforce at the gateway or a shared middleware layer so every route inherits a default, then tighten specific endpoints.
Shared state matters. Per-instance counters mean an attacker gets the limit multiplied by your instance count, which quietly removes most of the protection as you scale horizontally.
Watch what it is catching
Log every limit breach with the endpoint, dimension and identity. These logs are an early warning system — a sudden rise in password reset limiting is somebody enumerating your users, and it is the sort of signal that arrives well before anything else does.
Also watch for legitimate users hitting limits. A limit tuned without that feedback eventually blocks your largest customer on their busiest day.
0 comments
Leave a comment