How it works
Introspection is part of the GraphQL specification. Every GraphQL server understands a few special fields, mainly __schema and __type, that return information about the API instead of data from it. Developer tools use them to offer autocomplete, documentation and query builders.
A client sends an ordinary GraphQL request whose query asks about the schema. The server answers with a structured description of what it can do. Unless the server is configured otherwise, anyone who can reach the endpoint can ask.
Introspection is a feature and not a bug. It becomes a security concern when it is open to the internet for an API that was never meant to be public.
What it looks like
This request asks the server to list its mutations, the operations that change data:
POST /graphql HTTP/1.1
Host: api.acme.test
Content-Type: application/json
{"query": "{ __schema { mutationType { fields { name } } } }"}A server with introspection enabled replies with the full list:
{"data": {"__schema": {"mutationType": {"fields": [
{"name": "updateProfile"},
{"name": "refundPayment"},
{"name": "setMemberRole"},
{"name": "exportAuditLog"}
]}}}}The front end may only ever call updateProfile. The attacker now knows that refundPayment, setMemberRole and exportAuditLog exist.
Why it matters to an attacker
Introspection removes the guessing. With a REST API, an attacker discovers endpoints one by one. With an open schema, every operation is listed, including internal and deprecated ones, which makes shadow API functionality easy to find.
The schema itself is rarely the vulnerability. It points to where the real ones may be:
- Privileged mutations that might lack a role check, which is broken function level authorization.
- Fields that take an ID, each a candidate for broken object level authorization.
- Sensitive fields on common types, such as a reset token on a
Usertype that the UI never requests.
What disabling it does and does not do
Turning introspection off in production takes the map away from casual attackers and automated tools. It is worth doing for private APIs, and it is not an access control.
The schema leaks in other ways. Many servers answer a misspelled field with a hint such as "Did you mean refundPayment?", and tools can use those hints to rebuild much of the schema. The front-end JavaScript and the mobile app contain every query the product uses. An attacker who knows an operation name can call it whether or not introspection is on.
If an operation is unsafe when its name is known, it is unsafe.
How to test for it
- Find the endpoint. Common paths are
/graphql,/api/graphqland/query. Check staging hosts too. - Send an introspection query, first without a session and again as an ordinary user.
- Try variations if it is refused. Send the query as a
GETrequest to check whether the block is a real server setting or a fragile filter. - Check for field suggestions by sending a slightly misspelled field name.
- Test authorization on what the schema reveals. This step produces the real findings.
Open introspection on its own is a low-severity or informational finding.
How to fix it
Disable introspection where it is not needed, and make sure nothing depends on the schema being secret. Most servers have a switch. Apollo Server, for example, accepts an introspection: false option.
The control that matters is authorization inside every resolver:
const resolvers = {
Mutation: {
refundPayment: async (_parent, { paymentId, amount }, ctx) => {
// Enforced on the server, so knowing the mutation name is not enough.
if (!ctx.user?.roles.includes("billing_admin")) {
throw new GraphQLError("Not allowed", { extensions: { code: "FORBIDDEN" } });
}
return ctx.billing.refund(paymentId, amount, ctx.user.workspaceId);
},
},
};Further hardening:
- Turn off field suggestions in production error messages.
- Use an allowlist of known queries, often called persisted queries, if only your own clients should call the API.
- Limit query depth and cost so nested queries cannot exhaust the server.
- Remove unused fields and mutations from the schema.
A public API that publishes its schema on purpose can leave introspection on. Then all protection rests on authorization, as described under API security.