GraphQL Introspection or Playground Enabled in Production Config
Flags hardcoded introspection: true, playground: true, or graphiql: true flags in GraphQL server configurations that expose your complete internal API schema in production.
- Rule Slug
- public-graphql-introspection-enabled
- Affected Files
- *
- Detection Method
- Deterministic Regex
Vulnerable Pattern vs. Hardened Fix
// graphql/server.ts (Apollo Server)
import { ApolloServer } from '@apollo/server';
export const server = new ApolloServer({
typeDefs,
resolvers,
introspection: true, // MEDIUM RISK: Hardcoded on in all environments
});// graphql/server.ts (Apollo Server)
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
const isProd = process.env.NODE_ENV === 'production';
export const server = new ApolloServer({
typeDefs,
resolvers,
introspection: !isProd,
plugins: isProd ? [ApolloServerPluginLandingPageDisabled()] : [],
});Why This Fails in Production
GraphQL introspection allows any client to query the special __schema and __type meta-fields to retrieve a complete, machine-readable blueprint of every query, mutation, subscription, input object, enum, deprecated field, and internal comment exposed by your API. Paired with an enabled GraphiQL or GraphQL Playground UI, it effectively hands external attackers an interactive documentation portal and query builder for your entire backend surface.
While disabling introspection is not a substitute for proper field-level authorization, leaving introspection: true hardcoded in production removes crucial friction against automated reconnaissance. Security scanners routinely send a single __schema query to /graphql endpoints to uncover forgotten admin mutations (such as deleteUser, updateBillingTier, or impersonateAccount), internal debug queries, unreleased beta features, and sensitive field names that were never linked in your public frontend.
Furthermore, exposed GraphiQL and Playground interfaces often allow attackers to craft deeply nested circular queries (for example, user -> posts -> author -> posts) rapidly to trigger Denial-of-Service (DoS) CPU and database exhaustion if query depth and complexity limits are not enforced alongside authorization.
The production-safe pattern is to gate introspection and interactive IDE endpoints strictly behind process.env.NODE_ENV !== "production" (or equivalent environment flags), combine that with persisted queries or depth limiting, and enforce strict resolver-level authentication on every field.
Remediation Steps
- 1Gate introspection and interactive IDE tools behind environment checks: introspection: process.env.NODE_ENV !== "production".
- 2Disable GraphiQL, Apollo Sandbox landing pages, and GraphQL Playground in production builds unless protected behind VPN or admin-only authentication.
- 3Pair disabled introspection with query depth limiting, cost/complexity analysis, and disabled field-name suggestions to block schema brute-forcing.
- 4Audit all discovered queries and mutations to verify strict object-level authorization inside every resolver.
Step-by-step production API security checklists on BackendRecipes.
Frequently Asked Questions
- If my resolvers check authentication properly, why bother disabling GraphQL introspection?
- Defense in depth. Introspection instantly reveals hidden admin mutations, legacy endpoints, and schema relationships that help attackers find authorization gaps and craft nested DoS queries.
- Does Apollo Server disable introspection automatically in production?
- Apollo Server disables introspection when NODE_ENV=production by default, UNLESS you explicitly hardcode introspection: true, which overrides the safe default and exposes your schema everywhere.
- How can my frontend team inspect the schema if production introspection is off?
- Keep introspection enabled strictly in local development and authenticated staging environments, or publish schema artifacts directly to an internal schema registry during CI.