GraphQL Security Testing: Introspection, Batching and Authorization Flaws
GraphQL security testing means checking a GraphQL API for the flaws its design makes easy: an exposed schema (introspection and field suggestions), brute force and denial of service hidden inside a single request (aliases, batching, deep nesting), and authorization that's enforced on some resolvers but not others. Because everything goes through one endpoint, usually POST /graphql, URL-based WAF rules and request-count rate limits often don't see the attack. This guide shows how to test each area against your own API, in the order an attacker would.
A quick note on safety: run the denial-of-service style tests against staging, not production. The queries below are read-only, but deeply nested or heavily batched queries can still exhaust resources.
Step 1: Find the endpoint
GraphQL usually lives at /graphql, but /api/graphql, /v1/graphql, /query and /gql are common too. Check your frontend bundles for the endpoint string and any persisted query hashes. A quick probe:
curl -s https://staging.example.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ __typename }"}'
# A GraphQL server answers: {"data":{"__typename":"Query"}}
If you have multiple subdomains, check each one. Teams often lock down the main API but leave a GraphQL endpoint on an admin or internal-tools subdomain. The API Endpoint Discovery scanner enumerates REST and GraphQL endpoints and hidden routes across a verified domain, and our shadow API discovery guide covers the manual process.
Step 2: Introspection and schema leakage
Introspection lets any client ask the API for its full schema: every query, mutation, type and field. It's useful in development and gives an attacker a full map of your API in production.
curl -s https://staging.example.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ __schema { queryType { name } mutationType { name } types { name kind } } }"}' \
| jq '.data.__schema.types[].name' | head -50
If that returns your type list, introspection is on. Look specifically for mutations with names like updateUserRole, impersonate, deleteOrg or anything prefixed admin, and for node/nodes fields on the root query type.
Disabled introspection isn't the end of the test
Default behavior varies by server. Apollo Server, for example, enables introspection by default unless NODE_ENV is set to production. Even when it's off, many servers return "Did you mean...?" suggestions on typos:
curl -s https://staging.example.com/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ usr { id } }"}'
# Vulnerable response: Cannot query field "usr" on type "Query". Did you mean "user"?
Tools like Clairvoyance use exactly this behavior plus wordlists to rebuild the schema when introspection is disabled. The OWASP GraphQL Cheat Sheet recommends disabling suggestions when introspection is disabled; Apollo exposes a hideSchemaDetailsFromClientErrors option that strips them, and recommends enabling it in production.
The GraphQL Foundation's own security guidance is blunt about this: disabling introspection is a form of security through obscurity and won't hide the API on its own. Treat schema exposure as a low-to-medium finding that makes everything else easier, not as the main event.
Step 3: Batching and alias abuse
This is the most GraphQL-specific class of bug. There are two ways to pack many operations into one HTTP request.
Aliases
Aliases let you call the same field many times in one query under different names. The OWASP cheat sheet shows the pattern for enumerating objects:
query {
a: user(id: "1001") { email }
b: user(id: "1002") { email }
c: user(id: "1003") { email }
}
The same trick applies to authentication. If OTP verification is a mutation, an attacker can try hundreds of codes in one request:
mutation {
t0: verifyOtp(code: "000000") { success }
t1: verifyOtp(code: "000001") { success }
t2: verifyOtp(code: "000002") { success }
}
To test, send a request with 2 aliases, then 50, then a few hundred (on staging) and check whether every alias executes. If your rate limiter counts HTTP requests, it counts this as one.
Array batching
Some servers accept a JSON array of operations in a single POST:
curl -s https://staging.example.com/graphql \
-H "Content-Type: application/json" \
-d '[{"query":"{ __typename }"},{"query":"{ __typename }"}]'
# Two results back means array batching is enabled
The OWASP cheat sheet lists what batching enables: object enumeration, brute forcing passwords, OTPs and session tokens, application-level DoS, and evasion of WAFs and proxy rate limits that "rely on looking at the raw number of requests." OWASP's API4:2023 Unrestricted Resource Consumption also calls out the "number of operations to perform in a single API client request (e.g. GraphQL batching)" as a limit APIs should set.
Fix: limit aliases and batched operations per request, rate-limit sensitive operations by count of executions rather than HTTP requests, and block batching entirely for login, OTP and password-reset mutations.
Step 4: Depth, breadth and cost
Cyclic relationships (album -> songs -> album -> songs...) let a client write queries whose cost grows exponentially. The OWASP cheat sheet gives an example of a query nested N levels deep, and one requesting posts(first: 99999999).
Test on staging by increasing depth gradually and watching response time. Also try a large first/limit argument on list fields and repeating the same field hundreds of times in one selection.
Fix: depth limiting, maximum page sizes, query cost analysis and timeouts. The cheat sheet points to MaxQueryDepthInstrumentation and MaxQueryComplexityInstrumentation for graphql-java, and graphql-depth-limit for JavaScript. If your API serves only your own clients, the GraphQL Foundation recommends trusted documents: an allowlist of pre-approved operations, so arbitrary queries are never executed.
Step 5: Authorization flaws
This is where the high-severity findings are. In GraphQL, authorization belongs in resolvers (or a layer they call), and every path to an object needs it.
Object-level checks across different paths
The same Invoice type may be reachable through invoice(id:), org { invoices }, user { org { invoices } } and a global node(id:). Developers often protect the obvious query and forget the others. The OWASP cheat sheet says to enforce authorization "on both edges and nodes" and cites a public HackerOne report where nodes were missing checks that edges had.
Test it with two accounts in different tenants:
# As user B, request user A's object via every path you found in the schema
query {
node(id: "SW52b2ljZTo5MDMxMQ==") {
... on Invoice { id total customerEmail }
}
}
Relay-style global IDs are often just base64 of Type:id, so decoding and re-encoding them is trivial. Check whether your schema exposes node/nodes:
jq '.data.__schema.types[] | select(.name=="Query") | .fields[].name' schema.json | grep -i node
(That command, from the OWASP cheat sheet, assumes schema.json holds a full introspection result.)
Field-level checks
A user may legitimately see another user's name but not their email or phone. OWASP's API3:2023 example is a reportUser mutation that returns the reported user's fullName and recentLocation. Since the client picks fields, request every sensitive field on every type reachable from a low-privilege account.
Mutations
Replay every mutation you find in the schema as a lower-privileged user, including ones your frontend never calls. Also check input types for fields like role, ownerId or orgId that the server shouldn't accept from the client.
Step 6: Configuration checks
- GET queries and CSRF: does the server execute queries or, worse, mutations sent via
GETor asapplication/x-www-form-urlencodedPOSTs? Both can enable cross-site request forgery. - IDE exposure: GraphiQL, GraphQL Playground or Apollo Sandbox reachable in production.
- Verbose errors and tracing: stack traces or tracing extensions in responses.
GraphQL Cop is a small Python utility that checks many of these in one run (introspection, field suggestions, alias overloading, batch queries, GET-based queries and mutations, GraphiQL, tracing/debug modes) and outputs reproducible cURL commands:
python3 graphql-cop.py -t https://staging.example.com/graphql
GraphQL security testing checklist
| Area | Test | Typical severity if it fails |
|---|---|---|
| Introspection | __schema query returns types | Low to medium |
| Field suggestions | Typos return "Did you mean" | Low |
| Alias batching | Many aliased operations run in one request | Medium to high (higher on auth mutations) |
| Array batching | JSON array of operations accepted | Medium to high |
| Depth / cost | Deep or huge queries aren't rejected | Medium |
| Object authorization | Other tenant's object via any path or node | High to critical |
| Field authorization | Sensitive fields readable by low-privilege users | Medium to high |
| Mutation authorization | Admin mutations callable by regular users | High to critical |
| CSRF | Mutations over GET or form-encoded POST | Medium |
| Exposed IDE / debug | GraphiQL, tracing, stack traces in prod | Low to medium |
Severity depends on the data involved; these are typical starting points, not fixed ratings.
Automated scanning vs. manual GraphQL testing
Scanners do well at introspection, suggestions, batching support, exposed IDEs and CSRF-style configuration. Authorization flaws across tenants and paths need authenticated sessions for multiple roles and someone (or something) reasoning about what each role should see. That's the same split described in our API security testing guide, and most of these issues map to items in the OWASP API Security Top 10.
SecurityInfinity's agents run read-only recon and web checks on domains you've verified, and every finding comes with evidence and exact remediation. For the authorization side, the Authenticated Startup Pentest (from $999 per application) includes testing across every user role, IDOR and API testing, a signed attestation letter and a free retest within 30 days. To check exposure first, start a scan on your GraphQL domain.
Frequently asked questions
Should I disable GraphQL introspection in production?
For APIs that only serve your own clients, generally yes, along with field suggestions and GraphiQL. But the GraphQL Foundation notes that disabling introspection alone is security through obscurity. Schemas can still be rebuilt from suggestions, client code or wordlists, so authorization and query limits remain the real controls.
What is a GraphQL batching attack?
A batching attack packs many operations into one HTTP request, either with aliases or a JSON array of queries. Attackers use it to enumerate objects or brute-force OTPs and passwords while appearing as a single request to WAFs and rate limiters, as described in the OWASP GraphQL Cheat Sheet.
Are GraphQL APIs less secure than REST APIs?
Not inherently. GraphQL has the same core risks as REST (broken authorization, injection, misconfiguration) plus some of its own, such as schema exposure, batching and expensive nested queries. The single endpoint and client-chosen fields mean authorization has to be enforced in resolvers for every path to the data.
What tools are used for GraphQL security testing?
Common open-source options include GraphQL Cop for configuration and DoS-style checks, Clairvoyance for recovering schemas when introspection is disabled, and InQL, an open-source Burp Suite extension for GraphQL schema analysis and query generation. Intercepting proxies such as Burp Suite handle the manual authorization testing.
How do I prevent GraphQL denial of service?
Limit query depth, page sizes and the number of aliases and batched operations per request; add timeouts and query cost analysis; and rate-limit by operation cost rather than HTTP request count. For first-party-only APIs, an allowlist of trusted documents blocks arbitrary queries entirely.