GraphQL security
| Class | Access control |
|---|---|
| Concerns | Schema discovery, query cost, batched guessing, authorization of fields and objects |
| Typical severity | Low for an open schema, up to Critical for a mutation with no authorization check |
| Affects | GraphQL servers such as Apollo Server, graphql-java, WPGraphQL and Supabase pg_graphql |
A GraphQL API answers every request at one address, and the client writes the request. Instead of a fixed route such as /api/orders/42, the browser sends a query that names the objects and fields it wants, nested as deep as the schema (the server's list of types and fields) allows, and the server runs a resolver for each field. A proxy that counts requests sees one request however much work the query asks for, so limits on cost and batching belong in the GraphQL server's own code.1
Introspection and schema discovery
Introspection is a built-in part of GraphQL: the fields __schema and __type return the schema itself, with every type, field, argument and mutation (an operation that changes data). Many servers ship with it on, together with the GraphiQL query console, and without any sign-in, so a caller can read deprecated fields and fields meant for internal use.1 Exposed API documentation and debug endpoints covers other development features left on in production. A short request is enough:
{ __schema { queryType { fields { name description } } } }Turning introspection off hides the schema listing only. Queries and mutations keep working, and an attacker can still guess field names. Many servers answer a misspelt field such as usr with a hint that names the real one, and enough wrong guesses rebuild the whole schema.12 In Apollo Server the option hideSchemaDetailsFromClientErrors removes these "did you mean" suggestions from validation errors; it is off by default and Apollo advises turning it on in production.3
Query depth and size
GraphQL itself puts no limit on how deep a query nests or how many items a list field returns.1 When two types point at each other, as an album lists its songs and each song names its album, a query can loop through the pair level after level, and each level adds database work. Nested lists grow the returned data exponentially, which is the reason for a separate, smaller limit on how deep lists may nest. A depth limit rejects the query before any resolver runs.2
A list argument such as posts(first: 99999999) loads a server without any nesting, a cheap route to a denial of service. Pagination caps the items one request returns. Libraries add the missing limits: graphql-depth-limit for JavaScript servers and MaxQueryDepthInstrumentation in graphql-java.1 The most complete form is query complexity analysis, which gives each field a weight, refuses a query whose total weight is over a maximum and charges the total against a budget per client.2
Batching and aliases
One HTTP request can hold many operations. Some servers accept a JSON array of queries in one POST body, and aliases let the same field appear many times in one query under different names.1 A sign-in step that checks a six-digit code can be attacked this way:
mutation {
a1: verifyCode(code: "000001") { ok }
a2: verifyCode(code: "000002") { ok }
a3: verifyCode(code: "000003") { ok }
# ... several hundred more
}A rate limit in Nginx or a gateway counts this as one request, and a web application firewall sees one request as well, so the brute-force attack on codes, passwords or session tokens goes through at full speed.1 The limits that work count inside the request: a cap on the number of operations and aliases per request, a count of objects each caller has requested, and a rule that sensitive mutations such as code checks run once per request.12 Rate limiting covers the request-level limit these sit beside.
Field and object access
Each resolver hands out data, so each one is a place where authorization can be missing. A check on the user query does not protect the same user reached through post.author, and fields named node or nodes fetch any object by its ID, the GraphQL form of an IDOR. Checks belong on both the path to an object and the object itself, and on mutations where an API is meant to be read-only.1
A rule copied into each resolver drifts out of step with its copies, and a user then sees different data depending on the route to it. One rule per object in the business layer, called by every resolver with the signed-in user from the request context, avoids the drift.4
WPGraphQL 0.2.3, a GraphQL plugin for WordPress, had several of these flaws. Researchers at Pen Test Partners, who reported them in March 2019, listed the API's queries with an introspection request, then found mutations that checked no permissions. The registerUser mutation accepted a roles argument, so anyone could create an administrator account on a site with open registration, and a query filtered on hasPassword: true returned the text of password-protected posts.5 The administrator registration was recorded as CVE-2019-9879, and version 0.3.0, released on 6 April 2019, fixed the reported issues.65
Server settings
Apollo Server turns introspection off when NODE_ENV is production, refuses batched arrays unless allowBatchedHttpRequests is set, leaves stack traces out of error answers in production, and has CSRF prevention on by default.37 Setting them in code removes the dependence on an environment variable:
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: false,
allowBatchedHttpRequests: false,
hideSchemaDetailsFromClientErrors: true,
includeStacktraceInErrorResponses: false,
maxRecursiveSelections: true,
});With maxRecursiveSelections: true, Apollo refuses an operation whose fragments (named pieces of a query that other queries reuse) would expand to more than 10,000,000 selections; a number sets a lower cap.3
Supabase serves a GraphQL API through the pg_graphql extension, which follows Postgres grants (the permissions each database role holds on a table) and row level security. A table or column the requesting role has no SELECT grant on disappears from that role's schema; rows are filtered by policies.8 From pg_graphql 1.6.0, in new projects created from 29 June 2026, introspection is off unless a schema opts in with a comment; older projects keep it on until the extension is upgraded.9 To remove a table from what visitors without a login can see:
revoke all privileges on public.orders from anon;Allowlisting goes furthest for an API that serves only its own frontend. With trusted documents, also called persisted queries, the build stores each approved query under an ID, usually its hash, and the server runs only queries it knows. A public API cannot use it, because outside clients write queries nobody has seen.2
Prompt for a coding agent
Review the GraphQL server in this project. Turn off introspection and GraphiQL in production, and turn off field-name suggestions in error messages. Add a maximum query depth, a cap on aliases and on operations per request, and a maximum page size on every list field. Keep HTTP batching off unless the frontend needs it. For every query, mutation and nested field that returns user data, check that an authorization rule for the signed-in user runs, including node and nodes fields, and move duplicated checks into one function per object. List each change and any resolver you could not confirm is protected.
In SecFlash
SecFlash reports an endpoint that answers introspection as SF-EXP-203 on the Exposure page. On Supabase projects, the Cloud page lists tables that appear in the GraphQL schema for visitors with no login as SF-CLD-516, and tables that appear for every signed-in user as SF-CLD-517.
See also
- Exposed API documentation and debug endpoints
- Authorization
- Insecure direct object reference
- Rate limiting
- Denial-of-service attack
- Brute-force attack
- OWASP API Security Top 10
- Mass assignment
- Row level security
- Database dumping
- Attack surface
- Category: Access control
References
- a b c d e f g h i OWASP. "GraphQL Cheat Sheet". OWASP Cheat Sheet Series.
- a b c d e "Security". Learn GraphQL. graphql.org.
- a b c Apollo Graph Inc. "API Reference: ApolloServer". Apollo Server documentation.
- back "Authorization". Learn GraphQL. graphql.org.
- a b Simone Q. (8 May 2019). "Pwning WordPress GraphQL". Pen Test Partners.
- back "CVE-2019-9879" (published 10 June 2019). OSV.
- back Apollo Graph Inc. "Operation Request Format". Apollo Server documentation.
- back Supabase. "Security". Supabase Docs, GraphQL.
- back Supabase (13 June 2026). "Breaking change in pg_graphql 1.6.0: GraphQL introspection disabled by default". Supabase Changelog.
External links
- GraphQL Cheat Sheet, OWASP Cheat Sheet Series
- Introspection, GraphQL documentation