GraphQL API Security: Introspection, Deep Queries and the Authorization Gap
GraphQL hands clients a flexible query language — and hands attackers a map of your whole schema if you let it. Here is how introspection, query abuse and missing authorization go wrong, and how to lock the endpoint down.
SelfSec Team 8 min read
Part 1 of 4From the GraphQL series
At a glance
CWE-200- Interpreter
- GraphQL execution engine and its resolvers
- Required condition
- The schema is discoverable and resolvers run without per-object authorization, cost limits or a CSRF-safe transport.
- Potential impact
- Schema disclosure, cross-account data access, cross-site mutations and resource exhaustion.
- Primary defense
- Authorize every resolver per object, bound query cost, accept only JSON POST and hide the schema in production.
Safe practice: use benign proof only, in a disposable local lab or on a system you are explicitly authorized to test.
On this page
GraphQL replaces a fleet of fixed REST endpoints with a single flexible one: the client describes exactly the data it wants, and the server resolves it. That flexibility is the appeal — and the risk. The same query language that lets a front-end fetch precisely what it needs lets an attacker ask for things the developers never meant to expose, as deeply and as often as they like.
GraphQL security problems are rarely a single dramatic bug. They are a cluster of defaults that are convenient in development and dangerous in production: an introspectable schema, no limit on query depth or cost, resolvers that fetch data without checking whether this caller is allowed to see this object, and transports that let another site send operations in the user's session. The OWASP Top 10:2025 maps the underlying weaknesses — information exposure (CWE-200), authorization through user-controlled keys (CWE-639) and cross-site request forgery (CWE-352) — to A01 Broken Access Control.
The mental model: one endpoint, four separate controls
A REST API spreads its decisions across many routes. A GraphQL API concentrates them behind one URL, so each control has to be applied deliberately at the right layer:
| Layer | What a default server allows | What production needs |
|---|---|---|
| Schema | Any client can introspect it, and errors suggest real field names | Introspection and suggestions off for untrusted clients |
| Query shape | Unlimited depth, aliases and batched operations | Depth, cost and batch limits |
| Data access | Resolvers run for whoever names an id | An authorization check on every object returned |
| Transport | Many servers execute GET and form-encoded requests | JSON POST only, or a header that forces a CORS preflight |
A gap in any one row is enough. Hiding the schema does not fix a resolver that skips authorization, and a perfect authorization layer still runs an unbounded query.
How it happens
The root cause is treating GraphQL as if the schema were a private contract. It is not — by default, any client can ask the server to describe itself. Introspection is built into the specification, and a typical setup leaves it on everywhere:
const server = new ApolloServer({ typeDefs, resolvers, introspection: true, });
With introspection enabled, the entire type system is queryable. A second, deeper problem hides in the resolvers. A field that looks innocent often fetches an object by id with no authorization check:
const resolvers = {
Query: {
user: (_, { id }) => db.users.findById(id),
},
};
Nothing here asks "is the caller allowed to read user id?" The resolver trusts the argument. And because GraphQL types reference each other, a single request can traverse those relationships to arbitrary depth — user → posts → author → posts → ... — with no ceiling on how much work the server will do.
A concrete attack
First the attacker maps the schema. A single introspection query returns every type, query and mutation, including fields that were never documented:
{ __schema { queryType { name } mutationType { name } types { name fields { name } } } }
The response reveals an adminUsers query and a resetPassword mutation the public front-end never calls. Now the attacker probes for broken object-level authorization, walking ids that are not theirs:
{ user(id: 1) { name email passwordResetToken } }
If the resolver returns another account's data, that is an IDOR straight through the API. Even with introspection disabled, error messages leak: a misspelled field often triggers a "did you mean…?" suggestion that rebuilds the schema one guess at a time. And a single deeply nested query can exhaust the server:
{ user(id:1){ posts{ author{ posts{ author{ posts{ id } } } } } } }
Each level multiplies the work the resolvers do, turning one request into a denial-of-service. The introspection, authorization and denial-of-service posts take each of these steps further.
GraphQL does not enforce authorization for you. Hiding a field from the documentation is not access control — if a resolver will fetch an object, an attacker who can name that object can reach it.
Cross-site requests through GET and form posts
GraphQL clients normally send POST requests with an application/json body. A browser will not send that cross-site without a CORS preflight, which the API can refuse. Many servers also execute operations sent as a query string or as a form-encoded body, and those are simple requests a browser sends from any page, along with the user's cookies:
GET /graphql?query=%7B__typename%7D HTTP/1.1
Host: api.example
If that returns {"data":{"__typename":"Query"}}, the operation executed without the JSON content type. A page on another site can then submit a form with a query field containing a mutation, and the API runs it in the victim's session. Read operations stay protected by the browser's same-origin policy, but any state-changing mutation becomes cross-site request forgery.
What an attacker gains
The combination of an open schema and weak per-field controls yields:
- Full schema disclosure — every type, query, mutation and hidden field, even when nothing is documented.
- Broken object-level access — reading or mutating records that belong to other users via guessable ids.
- Classic injection through resolver arguments — SQL, NoSQL or command injection where an argument reaches a backend unsanitized.
- Cross-site mutations — state changes triggered from another site through GET or form-encoded requests.
- Denial of service — deeply nested or aliased queries that amplify one request into massive server work.
The fix: lock the schema, bound the query, authorize every field
GraphQL needs defenses at four layers: control who can see the schema, control how expensive a query may be, enforce authorization inside the resolvers themselves, and accept operations only over a transport a cross-site page cannot forge. With Apollo Server 4.11 or later:
import { ApolloServer } from '@apollo/server'; import { GraphQLError } from 'graphql'; import depthLimit from 'graphql-depth-limit'; import { createComplexityLimitRule } from 'graphql-validation-complexity'; const production = process.env.NODE_ENV === 'production'; const resolvers = { Query: { user: async (_, { id }, ctx) => { if (!ctx.user) { throw new GraphQLError('Authentication required', { extensions: { code: 'UNAUTHENTICATED' } }); } const user = await db.users.findById(id); if (!user || !ctx.can('read', user)) { throw new GraphQLError('Not authorized', { extensions: { code: 'FORBIDDEN' } }); } return user; }, }, }; const server = new ApolloServer({ typeDefs, resolvers, introspection: !production, hideSchemaDetailsFromClientErrors: production, csrfPrevention: true, validationRules: [depthLimit(7), createComplexityLimitRule(1000)], });
The authorization check runs against the object the resolver loaded, not just the fact that someone is signed in. hideSchemaDetailsFromClientErrors strips the "did you mean" suggestions from validation errors, and csrfPrevention, on by default since Apollo Server 4, rejects GET and form-encoded requests unless they carry a JSON content type or a header that forces a preflight. On other servers, reject GET for mutations, refuse any content type other than application/json, or require a custom request header.
The essential controls:
- Disable introspection in production so the schema is not handed out for free, and suppress field suggestions in error responses.
- Enforce query depth and complexity limits to cap how much work any single request can demand.
- Apply per-resolver, object-level authorization — every field that returns data must check that the current caller may see this object, not just that they are logged in.
- Accept operations only as
POSTwithapplication/json, or require a non-simple header, so cross-site pages cannot trigger mutations. - Validate and parameterize resolver inputs exactly as you would any other untrusted argument, and rate-limit the endpoint to blunt batching and aliasing abuse.
Fixes that do not hold
- Disabling introspection alone: field suggestions, client bundles and persisted queries still reveal the schema, and every resolver remains reachable by name.
- Checking authentication at the gateway only: a signed-in user can still request someone else's object unless each resolver checks ownership.
- Hiding fields from the documentation: an undocumented field is still executable.
- Rate limiting by request count: one request can carry hundreds of aliased fields or a batch of operations.
- Depth limits without cost limits: a shallow query with wide lists or many aliases can still be expensive.
- Relying on CORS for mutations: simple GET and form-encoded requests never trigger a preflight, so CORS headers do not stop them from executing.
A developer review checklist
- Disable introspection and field suggestions for untrusted clients in production.
- Put an object-level authorization check in every resolver that returns or changes data, including nested fields.
- Enforce depth, complexity and batch limits, and set timeouts on resolver work.
- Accept operations only as JSON
POST, or require a preflight-forcing header, and never run mutations over GET. - Parameterize every resolver argument that reaches a database, shell or downstream API.
- Log and rate-limit by authenticated principal as well as by IP address.
References
- OWASP Top 10:2025 — A01 Broken Access Control
- OWASP GraphQL Cheat Sheet
- PortSwigger Web Security Academy: GraphQL API vulnerabilities
- MITRE CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
- MITRE CWE-352: Cross-Site Request Forgery (CSRF)
- Apollo Server documentation: Preventing cross-site request forgery
- Module
- GraphQL
- How it probes
- Takes endpoints seen during the crawl, confirms ten well-known paths with a __typename query, then tests introspection, field-suggestion errors and GET and form-encoded transports; operations recovered from the schema and captured GraphQL-over-WebSocket frames carry the other modules' injection payloads into their arguments.
- How it confirms
- The introspection finding needs a parsed __schema object, the transport finding needs a GET or form-encoded request to return executed data rather than just a 200, and the suggestion finding needs Did you mean hints or an engine signature inside a genuine GraphQL errors array.
A reflected response alone is not enough to promote a GraphQL finding. The classical engine has to confirm the behavior before it reaches the report. See the detection engine
Find GraphQL in your own app
Reading about the class is one thing. SelfSec tests for it against an application you are authorized to assess, and only calls it real when independent evidence agrees.