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.

Lesson 27 of 69 · 12 min read · practice only with authorization

Diagram

One query, many resolvers

Follow the path. One example at a time.

Step 1 of 4

Query

A client asks for nested fields in one request.

Illustration: Query
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.

  1. Resolver authorization

    What fails
    GraphQL has no built-in authorization; each resolver must check.
    Who is affected
    Users whose nested objects are reachable through another type.
    What you would notice
    A user query that returns any user’s orders.
    What you change
    Centralize checks in the data layer or a directive applied to every field.
  2. 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.
  3. 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.

1 / 3

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.

  1. MapAPI security as an environmentModern products are APIs with a few front ends.
  1. 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.
  2. 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.
  3. 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.
  4. 04Unsafe consumption of third-party APIs: treating partner data as trustedWhen your service calls a partner or SaaS API, its responses are input too.
  5. 05API inventory gaps: shadow, zombie, and undocumented endpointsYou cannot protect APIs you do not know about.

Practice

  1. LabScope deskDecide whether a situation is in scope, needs a written change, or stops.

Glossary

  1. CardSecurity misconfigurationDefault accounts, open storage, verbose errors, or unused admin ports expose more than the product needs.