Disabling introspection and hardening
Turning introspection off hides the schema map but does not secure an API. See what still leaks, then cover GraphiQL, error masking and batching.
IntrospectionAuthentication and authorizationQuery depth and complexity limits
Disabling introspection and hardening
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Introspection lets anyone list every type and field in your schema, which is a free map for an attacker.
- Disabling introspection in production is reasonable hygiene, but field-name suggestions in error messages can still reveal the schema.
- Security through obscurity does not replace authorization, depth and cost limits, and rate limiting.
- Turn off GraphiQL, mask internal errors, and cap batching and aliases as part of the same hardening pass.
- Test your own API the way an attacker would, starting with an introspection query and a few misspelled fields.
What introspection gives away
Introspection is a feature of the spec: a client can ask the server for its own schema with the __schema and __type fields. It powers GraphiQL’s autocomplete, documentation tools and code generation. It also hands a stranger a complete list of every type, every field, every argument and every mutation, including the ones you never put in the docs.
That does not make your API vulnerable by itself. A schema is a description, not a permission. But an attacker who reads it knows where to aim: the deleteUser mutation, the internalNotes field, the admin queries. The point of hardening is to stop handing that over for free and to make sure that reading it achieves nothing.
Turning it off
In GraphQL Yoga this is a plugin. I ran @graphql-yoga/plugin-disable-introspection 3.1.0 with Yoga 6.1.0:
import { useDisableIntrospection } from "@graphql-yoga/plugin-disable-introspection";
const yoga = createYoga({ schema, graphiql: false, plugins: [useDisableIntrospection()] });
A { __schema { types { name } } } query then came back with GraphQL introspection has been disabled, but the requested query contained the field "__schema" and code GRAPHQL_VALIDATION_FAILED. { __typename } still worked, since that field is harmless and clients use it constantly. Yoga allows the plugin to be switched on conditionally, so the usual setup is: introspection on in development, off in production.
Two other defaults need the same attention. With graphiql: false, a browser request for the page got HTTP 406 instead of an in-browser IDE; by default Yoga served the GraphiQL page as HTML at the endpoint. And errors: Yoga masks unexpected resolver errors as “Unexpected error.” by default (seen in calling GraphQL with fetch). Keep that on in production, because raw database errors leak table names and query text.
What still leaks
This is the part to take seriously. With introspection disabled, I sent a misspelled query:
{ bok { title } }
The server answered Cannot query field "bok" on type "Query". Did you mean "book" or "books"?. The validation layer from graphql-js suggests close matches, and that is on by default. An attacker with a wordlist can recover most of your field names this way, one misspelling at a time, and public tools automate it. Some servers and plugins can mask the suggestions; check your server’s documentation, because I did not test a suppression option here.
So disabling introspection is a speed bump. It keeps casual scanners out and it removes the easiest discovery step, and that is worth a line of configuration. It is not access control. Never rely on a field being unknown. Any field an attacker finds must refuse them on its own, which is the job of authorization at the field level.
The rest of the pass
Hardening is a checklist more than a setting:
- Authorization on every path. Not just top-level fields.
- Depth and cost limits. See the previous lessons.
- Rate limits per user, IP and sensitive field, from rate limiting.
- Batching and alias caps. One request can hold many aliased calls to a login mutation, which gets around a per-request counter. Several password guesses in one HTTP request is a known GraphQL trick. Count operations and aliases, not just requests.
- An allowlist where clients are known: persisted queries.
- No GraphiQL or playground in production, or put it behind authentication.
- Masked errors and no stack traces.
- GET for queries only and CSRF care if you use cookies. Mutations over GET should be refused, as Yoga does (I saw a 405).
- Subscriptions with authentication on connection, and limits on concurrent subscriptions.
- Timeouts on requests and database statements.
The broader context is in the OWASP API Security Top 10, which applies to GraphQL as much as REST.
The tooling cost
Disabling introspection breaks tools that fetch the schema from the live server. Codegen configured with a URL stops working against production; point it at a committed SDL file or at a staging server where introspection is on. Schema registries, covered in the registry lesson, are the cleaner answer because the schema is published at build time instead of being pulled from production.
Test like an attacker
Run an introspection query against your own production URL. Try a misspelled field. Try a deep query, a batch of aliases, and a mutation over GET. If you can run a scanner against a staging environment, do so. The video below shows the attacker’s side of these steps.
What the video covers
Intigriti’s “Introduction to GraphQL Attacks” is a 19-minute video from March 2024 aimed at bug-bounty hunters. Its chapters include an intro, GraphQL API vulnerabilities, what is GraphQL, how it works, schemas, queries and mutations, and components of queries and mutations, so a good share of the front is a GraphQL primer you can skip. I only saw the first eight or so chapter titles and could not read a transcript, so I am not claiming how it treats introspection in detail; its subject is attacking GraphQL APIs, which is why it was chosen. It is the attacker’s view of why this lesson’s checklist exists. The runners-up are StackHawk’s five-minute best-practices overview, which lists introspection management as an item, and a two-minute introduction to introspection by Jamie Barton.
Where this fits
Hardening protects the API from abuse. The last lesson in this group, caching GraphQL, covers making it faster without leaking one user’s data to another.
Check yourself
Does disabling introspection stop an attacker from learning field names?
No. Many servers suggest close matches in validation errors, and tools can guess names from a wordlist, so hiding introspection only slows discovery.
Why is hiding the schema not a substitute for authorization?
An attacker who learns or guesses a field can still call it, so each field must enforce who may read it regardless of whether the schema is public.
What should you check before disabling introspection for a team that uses code generation?
Whether the schema is fetched from the running server in development or CI. Use a committed schema file or keep introspection on in non-production environments.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.