Skip to main content
Be Bitwise

Rate Limiting & Resource Exhaustion

API Vulnerability Classes · API Security track

6 min read

In this module

Why APIs Need Rate Limiting

Every API call burns resources: CPU cycles, memory, database connections, network bandwidth. Without a cap on how many requests a client can fire, one user (or one bored attacker with a Python script) can flatten the system. Rate limiting is the mechanism that holds the line, but APIs implement it poorly more often than they implement it well.

Unrestricted Resource Consumption (OWASP API4) is about much more than denial of service. Missing rate limits open the door to brute-force attacks on login endpoints, mass enumeration of BOLA-vulnerable objects, credential stuffing at scale, and automated abuse of business-critical flows.

How Rate Limiting Works

Rate limiters typically count requests per client using some mix of identifiers: IP address, API key, authentication token, user account. A handful of algorithms dominate:

  • Fixed window: count requests inside a fixed time period (say, 100 per minute). Simple, but vulnerable to burst attacks right at the window boundary.
  • Sliding window: track requests over a rolling period to smooth out those boundary effects.
  • Token bucket: each client has a bucket that refills at a fixed rate, and each request burns a token. Lets clients burst within reason while keeping the long-term average sane.

Rate limit state usually rides along in response headers:

http
HTTP/1.1 200 OK
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 73
X-RateLimit-Reset: 1709254800

Once the limit's blown, the server replies with 429 Too Many Requests.

Rate Limiting Is Not Just About DoS

Rate limiting protects against far more than denial of service. Without it, attackers can brute-force passwords, enumerate user accounts, scrape entire databases through BOLA, and automate business logic abuse - all at machine speed.

Bypass Techniques

IP-Based Rate Limiting Bypasses

When rate limiting hangs off the client's IP address, several bypasses are on the table:

Header manipulation: many APIs sit behind reverse proxies and trust headers like X-Forwarded-For for the real client IP. If the API trusts those headers from the wider internet without validation, an attacker can rotate spoofed IPs on every request.

http
GET /api/v1/login HTTP/1.1
X-Forwarded-For: 10.0.0.1
X-Real-IP: 10.0.0.1
X-Originating-IP: 10.0.0.1

IP rotation: spreading requests across proxy pools, VPNs, or cloud provider IP ranges so no single source ever crosses the per-IP threshold.

Account-Based Rate Limiting Bypasses

When rate limiting hangs off the authenticated user or API key, attackers fall back on familiar tricks:

  • Spin up multiple accounts and fan requests across them
  • Hit unauthenticated endpoints that don't track per-user counts at all
  • Exploit endpoints that don't share rate-limit counters with each other

Endpoint Variation

Rate limiters that track specific URL paths can be cheated by tweaking the request format:

http
GET /api/v1/users/1842
GET /api/v1/users/1842/
GET /api/v1/users/1842?
GET /api/v1/./users/1842
GET /API/V1/USERS/1842

If the rate limiter treats those as distinct endpoints while the backend resolves them all to the same handler, each variation hands the attacker a fresh counter.

GraphQL Batching Bypass

GraphQL hands attackers a uniquely elegant rate-limit bypass. Multiple operations can be bundled into one HTTP request, so a request-based rate limiter sees one ping when in reality the server is processing hundreds of operations.

graphql
[
{ "query": "{ user(id: \"1\") { email } }" },
{ "query": "{ user(id: \"2\") { email } }" },
{ "query": "{ user(id: \"3\") { email } }" },
{ "query": "{ user(id: \"4\") { email } }" }
]

One HTTP request carrying 100 batched queries performs 100 database lookups while burning a single unit of request-based rate limit. That's why GraphQL APIs are particularly juicy targets for enumeration attacks.

GraphQL Batching

GraphQL query batching allows multiple queries in a single HTTP request. This bypasses request-based rate limiting entirely. Effective protection requires counting individual operations within each request, not just the number of HTTP requests.

Resource Exhaustion via Expensive Queries

It's not just about request volume. A single computationally expensive request can drain resources just as effectively as a flood:

Deep Pagination

Pagination endpoints without an upper bound on per_page will gleefully cough up enormous data sets on demand:

http
GET /api/v1/transactions?page=1&per_page=1000000

Complex Filtering and Sorting

Letting clients pass arbitrary sort or filter expressions invites costly database work:

http
GET /api/v1/products?sort=CASE WHEN 1=1 THEN name ELSE price END

Large Request Bodies

File upload endpoints and bulk import APIs without payload size limits can consume disk and memory:

http
POST /api/v1/import HTTP/1.1
Content-Type: application/json
Content-Length: 524288000
[... 500MB of JSON data ...]

Regular Expression Denial of Service (ReDoS)

APIs that use user-supplied regular expressions for search or filtering are vulnerable to crafted patterns that cause catastrophic backtracking in the regex engine, consuming CPU for minutes on a single request.

Effective Rate Limiting Strategy

Proper rate limiting for APIs requires multiple layers:

  1. Per-user and per-IP limits: Apply both, so a single user cannot exhaust the system and a single IP cannot attack multiple accounts.
  2. Per-operation counting for GraphQL: Count individual queries within a batch, not just HTTP requests.
  3. Response size limits: Cap the number of records returned per request and enforce maximum payload sizes.
  4. Query complexity analysis: For GraphQL, calculate query cost based on depth, breadth, and requested fields before execution.
  5. Timeout enforcement: Set strict timeouts on database queries and API processing to prevent single expensive requests from blocking resources.
  6. Per-message rate limiting for WebSockets: WebSocket traffic bypasses HTTP rate limiters entirely, so message-level limits are essential.

Rate limiting is a prerequisite for every other security control. Without it, any vulnerability that exists can be exploited at scale. In the next lesson, we will explore a vulnerability class that no rate limiter can prevent: business logic flaws.