# GraphQL Denial of Service
> Resource exhaustion driven by a single client-shaped document — nesting, fan-out, aliases, duplication, fragments or directives — or by bugs in the parser, validator and query planner that process it before any resolver runs.
## How it works
Cost in GraphQL scales with the shape of the query, not the request count, and by default depth and list size are unbounded. A secondary reason: the language is far harder to parse, normalize and validate than a URL, so each stage (parse → normalize/inline fragments → validate → plan → execute) has its own exhaustion bugs.
### Query-shape vectors
| Vector | Shape |
|---|---|
| Depth / cyclic relationships | Bidirectional edges (`Paste.owner.pastes...` in DVGA, `searchGroups{users{groups{users...}}}`) grow work exponentially with depth |
| Amount / pagination bypass | `searchGroups(name:"", limit:1000000)` or unbounded list fields |
| Alias overloading | Same expensive field/mutation N times under aliases (see [[GraphQL Batching Attacks]]) |
| Field duplication | Same field repeated in one selection set; cheap to send, may be resolved repeatedly depending on engine |
| Directive overloading | Many directives on a field hammer validation |
| Fragment expansion | Deeply nested, reused named fragments expand exponentially |
| N+1 fan-out | Nested lists trigger one backend call per element absent DataLoader-style batching |
```graphql
query evil { # depth 0
album(id: 42) { # 1
songs { # 2
album { # 3
songs { ... } # N
```
### Engine / infrastructure CVEs
- **Apollo Router CVE-2025-32034** — named fragments expanded once per spread during query planning → exponential cost. Fixed in 1.61.2 / 2.1.1 with a "Query Fragment Expansion Limit"; only workaround was operation safelisting.
- **Apollo Compiler CVE-2025-31496 (CVSS 7.5)** — same fragment-reuse pattern hits validation; fixed 1.27.0.
- **graphql-core CVE-2026-119286** — `validate` reused a shared `ValidationAbortedError` instance that accumulated traceback frames across repeated validation errors → unbounded memory growth; fixed 3.3.1.
- **Directus GHSA-g293-vf99-xv36** — anonymous alias amplification of argon2id hashing, SMTP sends and lockouts on `/graphql/system`.
- **HackerOne $12,500** — aliased `verifyAccountRecoveryPhoneNumber` degraded account recovery.
- **CVE-2026-22014 (persisted-query fallback)** — server fell back to the client-supplied `query` when `queryId` was unknown, voiding the allowlist and re-enabling arbitrary expensive queries.
- **Saleor GHSA-24jw-f244-qfpp** — unbounded JSON-array batching; each element passed the per-query complexity limit, the request as a whole blocked uvicorn async workers and exhausted DB connections.
- **SurrealDB GHSA-p3c2-wh5f-jwqm** — `GET /graphql` WebSocket upgrade omitted the five `max_frame_size` / `max_message_size` / buffer bindings present on `/rpc` and `/sql`, so tungstenite defaults applied (16 MiB frame, 64 MiB message, `usize::MAX` write buffer). Anonymous sessions only needed namespace and database names in headers; lowering `SURREAL_WEBSOCKET_MAX_MESSAGE_SIZE` (the mitigation for the earlier GHSA-65rj-r9fh-jp2v) gave false coverage. Fixed in 4.0.0; interim `--deny-http graphql` or proxy-level frame limits.
## Testing
- Map cycles from the schema (InQL flags circular references), then step depth upward on staging and record latency and response size; OWASP's advice is literally to try to crash staging first.
- Separate limits: a depth rule rejecting depth ≥5 at validation still let 50 aliases of an in-limit query through — depth limit is not a cost limit.
- Probe alias count, token count, payload size, list `limit`/`first` caps, fragment nesting and directive counts independently.
- graphql-cop ships four DoS-class checks (alias overloading, array batching, directive overloading, circular introspection) alongside its misconfiguration tests; wrappers typically switch them off in stealth runs.
- Keep it bounded and get written permission: availability findings on prod are rarely in scope without it.
## Defenses
- Depth limit: `graphql-depth-limit` (`validationRules: [depthLimit(7)]`), graphql-java `MaxQueryDepthInstrumentation`; Hasura and Graphene expose depth settings.
- Cost analysis: graphql-java `MaxQueryComplexityInstrumentation`, JS cost-analysis libraries; enforce a maximum cost per operation and rate-limit on cost, not requests.
- Operation limits: GraphOS depth, height, aliases and root fields; GraphQL Armor max-aliases / max-tokens / max-depth; maximum request bytes.
- Envelope limits: cap JSON-array length and body size; apply WebSocket frame, message and buffer limits on every upgrade route via one shared helper so a new route cannot miss them.
- Timeouts at the resolver/application layer (stops work mid-query) plus infrastructure timeouts (nginx/httpd) as a backstop.
- Paginate every list with server-enforced maxima; DataLoader for N+1.
- Persisted/safelisted operations — and reject, never fall back, on unknown IDs.
- Patch engines: router, compiler and validator bugs bypass app-level limits.
## Related
- [[GraphQL Security]]
- [[GraphQL Batching Attacks]]
- [[API Rate Limiting]]
- [[API Fuzzing]]
- [[OWASP API Security Top 10]]
## Sources
- [[raw/checkmarx.com/exploiting-graphql-query-depth-4764|Exploiting GraphQL Query Depth]]
- [[raw/escape.tech/cyclic-queries-and-depth-limiting-escape-4402|Cyclic Queries and Depth Limiting (Escape)]]
- [[raw/github.com/apollo-router-query-planner-excessive-resource-consumption-via-named-f-4769|Apollo Router Query Planner Excessive Resource Consumption via Named Fragment Expansion]]
- [[raw/ameeba.com/cve-2025-31496-graphql-query-vulnerability-in-apollo-compiler-leading-4761|CVE-2025-31496: GraphQL Query Vulnerability in Apollo Compiler Leading to DoS]]
- [[raw/security.snyk.io/graphql-core-unbounded-memory-growth-cve-2026-119286-13384|graphql-core unbounded memory growth (CVE-2026-119286)]]
- [[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/infosecwriteups.com/how-graphql-mutation-aliasing-led-to-a-12-500-dos-bug-in-hackerone-s-a-8836|How GraphQL Mutation Aliasing Led to a $12,500 DoS Bug in HackerOne’s Account Recovery]]
- [[raw/github.com/graphql-persisted-queries-allowlist-bypass-via-id-manipulation-14897|GraphQL persisted queries allowlist bypass via ID manipulation]]
- [[raw/wundergraph.com/the-complete-graphql-security-guide-fixing-the-13-most-common-vulnerab-4185|The Complete GraphQL Security Guide: Fixing the 13 Most Common Vulnerabilities]]
- [[raw/tyk.io/graphql-security-7-common-vulnerabilities-and-mitigations-3129|GraphQL Security: 7 Common Vulnerabilities and Mitigations]]
- [[raw/medium.com/how-graphql-batching-and-field-duplication-enable-denial-of-service-15325|How GraphQL Batching and Field Duplication Enable Denial of Service]]
- [[raw/dedsecops.com/confirming-graphql-dast-findings-introspection-batching-depth-cost-csr-14495|Confirming GraphQL DAST findings: introspection, batching, depth/cost, CSRF over GET]]
- [[raw/cheatsheetseries.owasp.org/graphql-cheat-sheet-owasp-2815|GraphQL Cheat Sheet]]
- [[raw/apollographql.com/enforcing-graphql-security-best-practices-with-graphos-4399|Enforcing GraphQL security best practices with GraphOS]]
- [[raw/redamon.org/graphql-security-testing-introspection-and-graphql-cop-15485|GraphQL Security Testing: Introspection and graphql-cop]]
- [[raw/github.com/saleor-dos-via-unbounded-graphql-query-batching-15819|Saleor: DoS via unbounded GraphQL query batching]]
- [[raw/github.com/surrealdb-graphql-websocket-missing-size-limits-memory-amplification-15822|SurrealDB GraphQL WebSocket missing size limits (memory amplification)]]