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

VectorShape
Depth / cyclic relationshipsBidirectional edges (Paste.owner.pastes... in DVGA, searchGroups{users{groups{users...}}}) grow work exponentially with depth
Amount / pagination bypasssearchGroups(name:"", limit:1000000) or unbounded list fields
Alias overloadingSame expensive field/mutation N times under aliases (see GraphQL Batching Attacks)
Field duplicationSame field repeated in one selection set; cheap to send, may be resolved repeatedly depending on engine
Directive overloadingMany directives on a field hammer validation
Fragment expansionDeeply nested, reused named fragments expand exponentially
N+1 fan-outNested lists trigger one backend call per element absent DataLoader-style batching
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.
  • graphql-core CVE-2026-134795 — the parser’s max_tokens limit was checked only after Lexer.lookahead had already tokenized consecutive comments, so an unauthenticated document consisting of long comment runs cost CPU and memory proportional to its size, regardless of the token limit. Affects 3.2.12–3.2.13 and 3.3.0rc1–3.3.1; fixed in 3.2.14 / 3.3.2. A token limit counts only the tokens it actually sees; cap raw body bytes as well (GHSA-5pww-59wv-hj9w).
  • 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.

Sources