GraphQL Testing
NAT provides specialized support for GraphQL APIs, including schema introspection, query fuzzing, injection detection, and authorization testing unique to GraphQL.
Quick start
nat scan --url https://api.example.com/graphql --graphqlNAT detects the GraphQL endpoint automatically when --graphql is set. If your endpoint is at a non-standard path, provide it with --graphql-endpoint:
nat scan --url https://api.example.com \
--graphql \
--graphql-endpoint /api/graphqlSchema introspection
NAT uses GraphQL introspection to discover the full schema — all types, queries, mutations, and subscriptions:
nat scan --url https://api.example.com/graphql --graphqlIf introspection is disabled (common in production), provide the schema directly:
nat scan --url https://api.example.com/graphql \
--graphql \
--graphql-schema ./schema.graphqlIf introspection is disabled on your production endpoint, NAT will still test via query fuzzing — but providing a schema significantly increases coverage.
What NAT tests in GraphQL APIs
Authorization
| Test | Description |
|---|---|
| Object-level auth | Access other users' data through direct ID substitution |
| Field-level auth | Query sensitive fields not intended for your role |
| Mutation auth | Execute mutations your role shouldn't allow |
| Subscription auth | Subscribe to events your role shouldn't see |
Injection
| Test | Description |
|---|---|
| SQL injection | Injected SQL in string arguments resolved by a database |
| NoSQL injection | MongoDB/DynamoDB operator injection |
| Directive injection | Malicious directives in queries |
| Alias-based injection | Bypass rate limiting via query aliases |
DoS / Resource exhaustion
| Test | Description |
|---|---|
| Query depth | Deeply nested queries that trigger N+1 problems |
| Query complexity | High-complexity queries without complexity limits |
| Batching attacks | Batch multiple expensive operations in one request |
| Alias amplification | Use aliases to repeat expensive resolvers in one request |
Information disclosure
- Schema leakage when introspection should be disabled
- Verbose error messages exposing resolver details
- Debug fields (
__typenameabuse,__schemaleakage)
Authentication with GraphQL
Most GraphQL APIs use token-based authentication:
nat scan --url https://api.example.com/graphql \
--graphql \
--auth-type bearer \
--token "$TOKEN"For multi-user authorization testing, provide a second token:
nat scan --url https://api.example.com/graphql \
--graphql \
--auth-type bearer \
--token "$USER_A_TOKEN" \
--secondary-token "$USER_B_TOKEN"This enables NAT to test cross-user resource access (BOLA) in GraphQL.
Custom queries
You can seed NAT with example queries and mutations to improve test quality:
nat scan --url https://api.example.com/graphql \
--graphql \
--graphql-queries ./example-queries.graphqlExample queries file:
# example-queries.graphql
query GetUser {
user(id: "1") {
id
email
name
orders {
id
total
}
}
}
mutation CreateOrder($input: OrderInput!) {
createOrder(input: $input) {
id
status
}
}Output and reporting
GraphQL findings are reported with the same severity scale as REST findings:
[HIGH] query GetUser — Broken Object Level Authorization
User A can access User B's order history via user(id: "...") query
[MED] query ListProducts — Unrestricted Query Depth
Depth-10 nested query executes without error or complexity limit
[LOW] __schema — Introspection enabled in productionDisabling introspection (recommended for production)
If NAT finds that introspection is enabled on your production endpoint, you should disable it:
# Apollo Server (Node.js)
const server = new ApolloServer({
schema,
introspection: process.env.NODE_ENV !== 'production',
})# Graphene (Python)
schema = graphene.Schema(query=Query, mutation=Mutation)
app = GraphQL(schema, introspection=False)Disabling introspection is a security hardening measure but is not a substitute for proper authorization controls. NAT will continue testing your API through query fuzzing even when introspection is disabled.
Next steps
- Test a GraphQL API (how-to) — step-by-step guide
- Authentication Configuration — configure auth
- Security Scanning — full OWASP coverage details