GraphQL Query Depth or Batching Not Limited
The GraphQL server places no limit on query depth, complexity, aliases or batched operations, so one request can exhaust server resources or carry thousands of guesses.
| Severity | Medium |
| CVSS 3.1 | 5.3 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L Open in the calculator |
| CVSS 4.0 | 6.9 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-770: Allocation of Resources Without Limits or Throttling |
| MITRE ATT&CK | T1499.003 Application Exhaustion Flood, T1110 Brute Force |
| Category | Insecure Design |
Description
A single GraphQL request can ask for a great deal of work. Where the schema has relationships that lead back on themselves (for example a user's posts, each post's author, and that author's posts), queries can be nested to any depth, and each level can multiply the number of records fetched. Aliases allow the same field or mutation to be requested many times in one query under different names, and many servers also accept batches: an array of separate operations in one HTTP request. The server applies no limit on query depth, complexity or cost, the number of aliases, the size of the lists returned, or the number of operations in a batch.
Two problems follow. Expensive queries can tie up the server and its database with only a few requests, so an unauthenticated or ordinary user can degrade or interrupt the API for others, which may also increase hosting costs where resources scale automatically. And because rate limiting is usually applied per HTTP request, a single request containing hundreds of aliased or batched sign-in, verification code or voucher operations passes through it: an attacker can make thousands of attempts at passwords, one-time codes or other guessable values in a few requests, bypassing rate limits and lockout that count requests. The typical impact is limited disruption, rising where a sensitive mutation such as sign-in or code verification can be batched.
The weakness is identified by sending progressively deeper nested queries and observing response times, by sending a query containing many aliases of the same field or mutation, and by sending a JSON array of operations, to see which are processed in full. Testing is kept to volumes that show the absence of limits without degrading the service.
Remediation
Limit the cost of each request, not just the number of requests:
- Enforce a maximum query depth and a query complexity or cost limit, rejecting queries that exceed them before execution. Many servers provide these as options or validation rules, and libraries such as
graphql-depth-limitandgraphql-query-complexityprovide them for graphql-js. - Limit the number of aliases, root fields and operations per request. Disable batching where clients do not need it (in Apollo Server, the
allowBatchedHttpRequestsoption controls this), and cap the number of operations in a batch where they do. - Enforce maximum page sizes on list fields, and set execution timeouts.
- Apply rate limits to sensitive operations, such as sign-in and code verification, per operation rather than per HTTP request, or exclude them from batching and aliasing.
- Where the API serves only known clients, accept only persisted queries (an allowlist of operations registered in advance) instead of arbitrary queries.
Confirm the fix by repeating the deep, aliased and batched queries and checking that they are rejected before execution, and that repeated sensitive operations in one request are limited.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.