# API Rate Limiting
> Rate limiting caps how often a client can perform an operation. Missing or weakly-keyed limits on login, OTP, reset, signup, search and export endpoints are OWASP API4:2023 (Unrestricted Resource Consumption). Most bypasses exploit a mismatch between the limiter's key and the operation it is meant to protect.
## How it works
- A limiter counts something (source IP, a header, session, cookie, path string, TCP connection, HTTP request) over a window and returns `429 Too Many Requests` when exceeded.
- The weakness appears whenever a tester can vary the counted value while the protected operation stays identical: a new `X-Forwarded-For`, a different path spelling, another HTTP/2 stream, another alias inside one GraphQL document.
- API4 has two halves. **Rate**: enumeration and guessing against auth endpoints. **Resource**: a single expensive request such as `page_size=20000`, argon2 hashing per call, or an SMTP send per call. In cloud environments the resource half is also a cost problem as autoscaling absorbs the load.
- The canonical impact is a short numeric OTP or reset code (10,000 values for 4 digits) protected only by a limiter that can be sidestepped.
## Techniques / testing checklist
These are the limiter-key confusions to verify during an authorized test (HackTricks, Syed Shahwar, Araoz):
**Change the key the limiter trusts**
- **Spoofed client-IP headers** when a proxy or app reads them from an untrusted client: `X-Forwarded-For`, `X-Originating-IP`, `X-Real-IP`, `X-Client-IP`, `X-Remote-Addr`, `X-Host`, `X-Forwarded-Host`, including a duplicated `X-Forwarded-For`.
- **Other client-controlled keys**: `User-Agent`, device ID, cookie, `Referer`. If rotating one changes the quota while the account and operation stay the same, the limiter is keyed to that value.
- **Anti-CSRF cookie keying**: a login throttle keyed to the CSRF cookie resets when you fetch a fresh login form (capture both the new cookie and its form token).
- **New session per attempt**: if the counter is per-session, re-issuing a session resets it; if the OTP counter is tied to the session ID but the "start session" endpoint is unthrottled, cycle sessions.
**Confuse the endpoint identity**
- **Path variants**: `/api/v3/sign-up` vs `/Sign-up` vs `/SignUp` vs `/api/v1/sign-up`. A bypass means canonicalization happens after the limit decision.
- **Route normalization**: append `/.` or `/..` so the request misses the rule but normalizes back to the same handler.
- **Ignored parameters**: `/resetpwd?x=1` — gateways that key on path+params give each distinct string its own quota.
- **HTTP method switch** (GET/POST/PUT/PATCH) and **CDN origin bypass** (hit the origin IP directly).
**Confuse the operation string**
- Delimiter/encoding mismatch in a username-keyed limiter: `
[email protected]%00`, `%20`, `%09`, `%0d`, `%0a`, or partial encoding `e%78ample@m%61il.com` — the auth code normalizes it while the limiter sees a distinct key.
- **HPP**: `code=1&code=2` or two `email=` params where the limiter and the auth logic pick different occurrences.
**Count units the limiter ignores**
- **HTTP/2 multiplexing**: a limiter that counts TCP connections but not request streams. `h2load -n 100 -c 1 -m 100 ...` (one connection, many streams); Turbo Intruder varies the body per stream while holding the connection.
- **Bulk/batch REST endpoints**: `/v2/batch` or an array body wrapping many operations when the limiter only fronts the single-operation routes.
- **GraphQL aliases**: one document invokes the same resolver many times under different names. See [[GraphQL Batching Attacks]].
- Two GraphQL notes disagree on which form works: a voucher check survived 50 array-batched entries but hit 504s at 5,000 aliases; Saleor's array batching had no cap at all. Test aliases and arrays separately.
- **WebSocket/gRPC after handshake**: edge WAFs that inspect the upgrade but not the messages inside.
- **Fixed-window boundary**: burst just before and just after a known `X-RateLimit-Reset`, approaching 2× the nominal allowance.
- **CDN PoP-sharded counters**: counters not shared across data centers give one quota per PoP.
**Don't close too soon.** Even with a limiter present, check whether the response differs for a correct OTP (a `429` may still process the submitted value).
## Notable cases
- **Single-packet amplification (RyotaK / Flatt Security).** Extends James Kettle's single-packet attack past its ~1,500-byte / 20–30-request limit using IP fragmentation plus TCP sequence reordering, holding the server from processing until the last packet arrives. Sent ~10,000 requests in ~166 ms, enough to beat a limiter on numeric one-time-token auth where a normal single-packet attack could only send 20–30. See [[Race Conditions]].
- **Directus (GHSA, `resolvers/system-global.ts`).** Un-deduplicated anonymous GraphQL resolvers (`auth_login`, `auth_password_request`, `utils_hash_generate`) let one unauthenticated `POST /graphql/system` with many aliases cause account-lockout DoS, password-reset mail flooding and many argon2id hashes per request — the HTTP limiter counts requests, not resolver invocations.
- **Overgrowth (HI CyberCon 2026 CTF).** Introspection was off but validation errors spelled out an unauthenticated `resetPassword(username, token, newPassword)` with a 4-digit code and no attempt counter; aliased mutations covered all 10,000 codes in ~3.5 s.
- **Zimbra (wrapper-dependent accounting).** The SOAP wrapper set the `auth.failed` request attribute on failure; the GraphQL path called the same handler without that wrapper, so the source-IP filter never incremented.
- **PortSwigger GraphQL brute-force lab.** A per-origin limiter counted HTTP requests; 100 aliased `login` mutations in one request each returned `success`, so one round trip held the whole password-list result. "The defense is counting the wrong unit" ([[raw/logicbreaker.sh/bypassing-graphql-brute-force-protections-15818|logicbreaker]]).
- **Voucher-code GraphQL endpoint (API4:2023).** Limit of 10 checks per request window bypassed via alias batching; thousands of aliases caused gateway timeouts, a potential denial-of-wallet on auto-scaling Azure ([[raw/medium.com/graphql-alias-batching-bypasses-rate-limiting-15820|Medium]]).
- **Saleor GHSA-24jw-f244-qfpp.** Unbounded JSON-array batching bypassed per-query complexity limits — the resource half of API4 ([[raw/github.com/saleor-dos-via-unbounded-graphql-query-batching-15819|advisory]]).
## Defenses
- Key limits to the **account or protected operation**, not to a client-controlled value. Count failed attempts per account and lock out after a handful; move to longer, time-boxed codes.
- Count the **logical operation** (resolver invocation, auth attempt), not HTTP requests or TCP connections. Instrument GraphQL resolvers and batch/bulk endpoints to charge per operation.
- Overwrite forwarded client-IP headers at a trusted edge; only honor them from known proxy hops.
- Enforce the same limiter on every version and spelling of a route, and on WebSocket/gRPC messages, not just the upgrade.
- Cap `page_size`/`max_return`; apply timeouts and concurrency limits; baseline per-parameter traffic (Salt's example flags `20000` against a learned 250).
## Related
- [[API Security]]
- [[OWASP API Security Top 10]]
- [[GraphQL Batching Attacks]]
- [[API Discovery]]
- [[Race Conditions]]
- [[Account Takeover]]
- [[MFA Bypass]]
## Sources
- [[raw/book.hacktricks.xyz/rate-limit-bypass-hacktricks-3996|Rate Limit Bypass - HackTricks]]
- [[raw/medium.com/bypassing-rate-limits-all-known-techniques-3995|Bypassing Rate Limits: All Known Techniques]]
- [[raw/iaraoz.medium.com/hacking-apis-bypassing-rate-limiting-3997|Hacking APIs: Bypassing Rate Limiting]]
- [[raw/salt.security/api4-2023-unrestricted-resource-consumption-4913|API4:2023 Unrestricted Resource Consumption]]
- [[raw/flatt.tech/beyond-the-limit-expanding-single-packet-race-condition-with-a-first-s-6120|Beyond the Limit: Expanding single-packet race condition for breaking the 65,535 byte limit]]
- [[raw/github.com/directus-unthrottled-system-graphql-resolvers-allow-anonymous-dos-via-13550|Directus unthrottled system GraphQL resolvers allow anonymous DoS via alias amplification]]
- [[raw/p4ndora.ai/overgrowth-graphql-aliased-mutation-brute-force-of-a-password-reset-hi-14207|Overgrowth: GraphQL aliased-mutation brute force of a password reset]]
- [[raw/sutlukader.medium.com/api-g-venli-inin-g-r-nmez-kahraman-rate-limiting-i-stek-s-n-rland-rma-12960|API Güvenliğinin Görünmez Kahramanı: Rate Limiting]]
- [[raw/medium.com/exploiting-all-10-owasp-api-security-risks-in-vapi-bonus-arena-challen-14687|Exploiting All 10 OWASP API Security Risks in vAPI (+ Bonus Arena Challenges)]]
- [[raw/logicbreaker.sh/bypassing-graphql-brute-force-protections-15818|Bypassing GraphQL brute force protections]]
- [[raw/medium.com/graphql-alias-batching-bypasses-rate-limiting-15820|GraphQL Alias Batching Bypasses Rate Limiting]]
- [[raw/github.com/saleor-dos-via-unbounded-graphql-query-batching-15819|Saleor: DoS via unbounded GraphQL query batching]]