CWE-770AvailabilitySeverity · Medium

Queries nested a hundred levels deep

A GraphQL or search query that nests relations many levels deep can force huge database work. One request like this can slow or stall a service.

At a glance

Controls
CWE-770
Typical severityMedium
ReferenceCWE-770

What it is

GraphQL and flexible search APIs let callers choose which related records to fetch. A query can ask for users, their orders, each order's users, and so on many levels down. The server may then run a vast number of database lookups for one request.

An attacker writes one deeply nested or very wide query and sends it a few times. The database stalls and other users see timeouts. AI tools can read a published schema and build the most expensive possible query almost at once.

Where it hides

What a reviewer can look for in the code and in the behaviour, before anyone proves it.

  • Public or partner GraphQL endpoints with circular relations
  • Schema introspection left on in production
  • Search APIs that accept nested filters or expansions
  • Batched requests that pack many queries into one call

How MATT tests it

The proof runs against the deployed product, on every release, whoever wrote the code.

  1. 01Sign in with the test login and read the schema to find relations that loop back on each other
  2. 02Send a query that nests these relations a few levels deeper than normal use needs
  3. 03Measure whether the server rejects it or how much response time grows, keeping depth low enough to avoid harm
The rule, in plain English

Query depth and cost must be capped.

Executable check

as any user: POST /graphql with a query nested 20 levels deep expect: 400 with a depth or cost error as any user: POST /graphql with a batch of 100 queries expect: rejected or limited

Every rule MATT holds →

What the fix looks like

  1. 01

    Set a maximum query depth on the server

  2. 02

    Give each field a cost and reject queries above a total cost

  3. 03

    Limit how many queries one request may batch

  4. 04

    Turn off introspection in production unless the API is meant to be public

A check that was never written is found by proving the deployed behaviour, fixed with the engineer who shipped it, and kept fixed by running the control on every change. What is ExploitOps? →

ExploitOps discovery call

Understand where your security loop breaks.

A call with a MATT co-founder to understand your product and whether an ExploitOps Review is worth doing. If there is a real need, we scope one with the research team.

Let’s understand your priority

What brings you to MATT?

What would you like help with?
01 / 02