GraphQL security: introspection, resolver authorization, and query cost
Where GraphQL APIs go wrong — missing authorization in resolvers, unbounded nested queries, batching that defeats rate limits, and injection in resolver code — and how to review a schema and test it with a tool like InQL or graphql-cop.
Diagram
One query, many resolvers
Step 1 of 4
Query
A client asks for nested fields in one request.
query { user(id: "42") { email orders { id total items { sku } } } }The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Query cost
- What fails
- Deeply nested or aliased queries multiply database work.
- Who is affected
- Everyone sharing the API’s capacity.
- What you would notice
- Single requests that take seconds and fan out to thousands of queries.
- What you change
- Set depth, alias, and cost limits; use persisted queries for first-party clients.
Injection still applies
- What fails
- Resolvers that build SQL or call shells have the same injection risks as REST handlers.
- Who is affected
- The data behind those resolvers.
- What you would notice
- String-built filters from GraphQL arguments.
- What you change
- Parameterize inside resolvers.
Reviewing a schema
Fetch the schema in a test environment (introspection or the SDL file), list every type that holds personal or tenant data, and for each path that reaches it, find the resolver and its authorization check. Mutations deserve the same review as REST write endpoints.
$ npx get-graphql-schema https://staging.example.test/graphql > schema.graphql $ grep -nE "^type (User|Invoice|Order)" schema.graphql $ graphql-cop -t https://staging.example.test/graphql [HIGH] Alias Overloading with 100+ aliases is allowed [LOW] Introspection is enabled
Batching and rate limits
GraphQL lets one HTTP request carry many operations or aliases, so per-request rate limits undercount. Count operations or cost instead, especially on login and OTP mutations.
Check yourself
Recognition and the fix. Nothing here is a procedure.
The top-level user resolver checks ownership, but orders under it do not. What happens?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
- 01Broken API authentication: tokens, keys, and the checks that get skippedCommon API authentication failures: unvalidated JWT claims, API keys in URLs, missing rate limits on token endpoints, and long-lived tokens.
- 02API security misconfiguration: defaults, debug modes, and permissive CORSThe configuration mistakes that turn a sound API into an exposed one: debug endpoints, verbose errors, wildcard CORS with credentials, open documentation consoles, and missing TLS settings, with a scan-and-fix workflow.
- 03Injection through API fields: JSON bodies reaching SQL, NoSQL, and shellsWhy JSON APIs are still injection targets: operator injection in MongoDB-style queries, typed fields that are never type-checked, and filter parameters passed to query builders.
- 04Unsafe consumption of third-party APIs: treating partner data as trustedWhen your service calls a partner or SaaS API, its responses are input too.
- 05API inventory gaps: shadow, zombie, and undocumented endpointsYou cannot protect APIs you do not know about.