Skip to main content
Be Bitwise

GraphQL Hacking

Advanced API Exploitation · API Security track

8 min read

In this module

Why GraphQL Is a Rich Target

GraphQL was designed to give clients maximum flexibility. That same flexibility hands attackers powerful tools for reconnaissance and exploitation. A single endpoint handles every operation. Introspection can dump the entire schema. Queries batch up to dodge rate limits. Deeply nested queries bring servers to their knees.

This lesson covers the core attack techniques specific to GraphQL APIs.

Introspection: Reading the Blueprint

Introspection is a built-in GraphQL feature that lets clients query the schema itself: every type, field, argument, and relationship. The reference implementation (graphql-js) and many servers leave it on unless you turn it off. Some switch it off for you in production: Apollo Server, for instance, disables introspection by default when NODE_ENV is production. Misconfigured, staging and self-built servers still expose it often enough that it's always worth trying first.

graphql
{
__schema {
types {
name
fields {
name
type {
name
kind
}
}
}
}
}

A single query returns the complete schema. For an attacker, it's equivalent to finding the full API documentation, including internal types and fields that were never meant to be public.

Introspection as Reconnaissance

GraphQL introspection, when it's left on, hands the attacker a complete map of every type, field, and relationship in the API. The REST equivalent would be finding a full OpenAPI specification, except this one's baked into the protocol itself.

Full Schema Extraction

A full introspection query pulls types, fields, arguments, enums, and input objects in one shot:

graphql
{
__schema {
queryType { name }
mutationType { name }
types {
name
kind
fields {
name
args {
name
type { name kind ofType { name } }
}
type {
name
kind
ofType { name kind }
}
}
}
}
}

Tools like GraphQL Voyager render the extracted schema as an interactive graph, making it easy to spot relationships between objects and map out attack paths. InQL (a Burp Suite extension) automates introspection and generates queries for every discovered endpoint.

When Introspection Is Disabled

Some production APIs disable introspection. That doesn't fully hide the schema, though. GraphQL's field suggestion feature leaks schema information even when introspection is off. Send a query with a misspelled field name and the server helpfully suggests similar valid field names.

graphql
{
user(id: "1") {
pasword
}
}

Response:

json
{
"errors": [{
"message": "Cannot query field 'pasword' on type 'User'. Did you mean 'password'?"
}]
}

Systematically firing misspelled field names based on common patterns lets an attacker rebuild huge swathes of the schema without introspection access. Tools like clairvoyance automate this field-name brute-forcing.

Nested Query Denial of Service

GraphQL's type system allows relationships between objects. When those relationships are circular or deeply nested, an attacker can craft queries that explode into an exponential number of database lookups.

graphql
{
user(id: "1") {
friends {
friends {
friends {
friends {
friends {
name
email
}
}
}
}
}
}
}

If each user has 100 friends, this query resolves to 100^5 = 10 billion database lookups. The client sent one tiny request. The server has to chew through a mountain of work.

Defence: Query Depth and Complexity Limits

Real protection requires analysing the query before execution:

  • Maximum depth: Reject queries that exceed a configured nesting level (typically 5-10 levels).
  • Query cost analysis: Assign a cost to each field based on the expected database work, and reject queries whose total cost exceeds a threshold.
  • Timeout enforcement: Kill queries that exceed a time limit, even if they pass depth checks.

Batching Attacks

As covered in the rate limiting lesson, GraphQL lets you cram multiple operations into a single HTTP request. The attack applications go beyond just bypassing rate limits.

Brute-Force via Batching

An attacker can batch hundreds of authentication attempts into one request:

json
[
{ "query": "mutation { login(user:\"admin\", pass:\"password1\") { token } }" },
{ "query": "mutation { login(user:\"admin\", pass:\"password2\") { token } }" },
{ "query": "mutation { login(user:\"admin\", pass:\"password3\") { token } }" }
]

Request-based rate limiters log this as a single request. Account lockout mechanisms that track failed logins per request also see only one request, which can let hundreds of password guesses slip through per lockout window.

Enumeration via Aliases

Even without batching, GraphQL aliases let you stack multiple instances of the same query inside a single operation:

graphql
{
u1: user(id: "1") { email }
u2: user(id: "2") { email }
u3: user(id: "3") { email }
u4: user(id: "4") { email }
}

It's a single query (not a batch), so it can sail past even batch-aware rate limiters.

Aliases as Enumeration

GraphQL aliases let you stack multiple copies of the same query field with different arguments inside a single request. That's batching-like capability inside a single operation, slipping past both request-level and batch-level rate limiting.

Mutation Abuse

GraphQL mutations modify server-side data. Combine them with introspection and an attacker can find administrative mutations that shouldn't be accessible at all:

graphql
mutation {
updateUserRole(userId: "1842", role: ADMIN) {
id
role
}
}

If authorisation checks on mutations are missing or wobbly, introspection hands the attacker the exact mutation name, argument types, and return fields needed to exploit them.

Testing Checklist

When testing a GraphQL API, work through these checks systematically:

  1. Attempt introspection - if it works, extract and analyse the full schema
  2. If introspection is disabled, use field suggestion exploitation to reconstruct the schema
  3. Test query depth limits - send increasingly nested queries and watch where the server cuts off
  4. Test batching limits - send batched operations and verify per-operation rate limiting
  5. Test alias enumeration - use aliases to perform multiple lookups in a single query
  6. Test mutations for authorisation - attempt administrative mutations with regular user credentials
  7. Check for verbose error messages - GraphQL errors often leak type information, field names, and internal structure

GraphQL's power and flexibility carve out a unique attack surface. The next lesson examines two more specialised API technologies, gRPC and WebSockets, along with the attack techniques specific to each.