Rate limiting and unrestricted resource consumption: protecting expensive endpoints
Which endpoints need limits (login, OTP, search, export, uploads, AI calls), how to choose keys and budgets, the 429 response and Retry-After, and how to test limits in staging without hurting production.
Diagram
Choosing what to limit
Step 1 of 4
Find cost
List endpoints that are expensive or abusable: login, OTP verify, password reset, search, export, upload, AI completion.
# Find cost # List endpoints that are expensive or abusable: login, # OTP verify, password reset, search, export, upload, AI # completion.
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
IP-only limits miss distributed abuse
- What fails
- Botnets and residential proxies spread attempts across many addresses.
- Who is affected
- Accounts targeted by stuffing and spraying.
- What you would notice
- Login limits keyed only by IP.
- What you change
- Add per-account and per-username limits and watch global failure rates.
Resource limits, not only request limits
- What fails
- One request can upload gigabytes, export a million rows, or request a huge AI response.
- Who is affected
- Everyone sharing the service, and the budget.
- What you would notice
- No caps on page size, upload size, or tokens.
- What you change
- Cap sizes, page lengths, timeouts, and concurrency per caller.
OTP brute force
- What fails
- Six-digit codes have a million values; without attempt limits they fall quickly.
- Who is affected
- Accounts protected by that OTP.
- What you would notice
- Unlimited verify attempts per code.
- What you change
- Limit attempts per code and per account and expire codes quickly.
Testing limits in staging
Send a controlled burst against a staging login with a test account and confirm the limit triggers at the configured number with a 429. Do not load-test production without an agreed window.
$ for i in $(seq 1 8); do curl -s -o /dev/null -w "%{http_code} " -d "user=test1&pass=wrong" https://staging.example.test/login; done; echo
401 401 401 401 401 429 429 429OWASP API4
The OWASP API Security Top 10 calls this unrestricted resource consumption: missing limits on execution time, memory, file size, records per page, and paid third-party calls such as SMS or AI APIs.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Login attempts come from thousands of IPs, a few each. Which limit helps?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.