Batching Attacks and Query Limits
What you'll learn: How attackers exploit GraphQL's batching feature to execute multiple expensive operations in a single request, bypassing rate limits and resource controls.
The Core Problem
GraphQL allows clients to send multiple queries in a single HTTP request through batching. While this improves efficiency for legitimate use, attackers can abuse it to:
- Execute hundreds of expensive operations in one request
- Bypass rate limits that count requests, not operations
- Consume massive server resources while appearing to make only "one" call
- Overwhelm cost analysis systems that evaluate queries individually
How Batching Attacks Work
Imagine a restaurant with a "one order per customer" rule. Most people order one meal. But what if someone orders "one meal" that consists of 100 steaks, 50 lobsters, and 200 desserts all at once? The rule technically isn't violated, but the kitchen is now completely overwhelmed.
Similarly, an attacker might send:
[
{ query: "{ expensiveSearch(limit: 1000) { ... } }" },
{ query: "{ expensiveSearch(limit: 1000) { ... } }" },
// ... repeated 100 times
]
Your rate limiter sees one HTTP request, but your server processes 100 expensive queries. Combined with the query complexity techniques you've learned, this becomes devastating.
Prevention Strategy
Implement batch-aware limits:
- Count batched operations individually against rate limits
- Set maximum batch size (e.g., 10 queries per request)
- Apply cumulative cost analysis across all batched operations
- Monitor total execution time for the entire batch
- Consider disabling batching entirely for public APIs
Key Takeaway: Rate limiting must account for batched operations by counting and costing each query in a batch individually, not just the HTTP request itself, to prevent attackers from bypassing resource controls through single high-volume requests.