Authorisation at the field level
- Checks in the top-level query resolver do not apply when the same type is reached through a relationship.
- Mutations that take an ID argument need ownership checks in the resolver, not just authentication in context.
- Directives such as @auth only work if the implementation covers every field they decorate.
- Error messages that echo whether an object exists help attackers enumerate IDs.
Query shape abuse
- Deeply nested or cyclic queries (user.posts.author.posts…) can exhaust resources without depth or cost limits.
- Aliases let a client run the same field hundreds of times in one request, which defeats per-request rate limits on login or OTP mutations.
- Array batching is off by default in Apollo Server 4 (allowBatchedHttpRequests), but alias batching still works.
- Field suggestions in error messages ('Did you mean…') leak schema details even with introspection off.
Federation and gateways
In a federated graph, the router or gateway typically handles authentication and forwards identity to subgraphs. If a subgraph is reachable directly, a client can query it without the router's checks and call the _entities field to fetch any entity by key. Subgraphs should only accept traffic from the router and verify the forwarded identity.
Injection behind resolvers
GraphQL does not remove injection; it moves it. Arguments passed from resolvers into SQL, MongoDB queries, shell commands or downstream REST calls need the same validation as any API input. Custom scalars such as JSON or Upload accept structured data that is easy to forget about, and file uploads through GraphQL multipart requests have been abused for CSRF where CSRF prevention was turned off.
Testing Apollo with Pentest-Swarm
Pentest-Swarm has a dedicated graphql-audit playbook covering introspection, field-level authorisation, injection and batching abuse, and it tests your endpoint over HTTP.
- Run graphql-audit against https://your-staging-host/graphql with scope limited to that host.
- Pass a test user's token with
--authto test field and mutation authorisation; repeat with a second user for cross-user access. - Include subgraph hostnames in scope if you want to test whether they are reachable directly.
- Practise first on the bundled DVGA lab, which ships deterministic chains for introspection and command-injection findings.
Where it falls short
With introspection disabled, a black-box tester has to infer the schema from client traffic and error messages, so coverage depends on what it can discover. Give the tester your schema for staging, add persisted queries or an operation allow-list in production, and review resolver authorisation in code.
Questions
Should I disable introspection in production?
For private APIs, yes; Apollo Server does this by default when NODE_ENV is production. It reduces reconnaissance but is not an access control.
How do I rate-limit GraphQL properly?
Limit by query cost or by operation and field, not only by HTTP request, because aliases put many operations into one request.
Is direct subgraph access a real risk?
Yes, when subgraphs trust the router to authenticate. Restrict them to private networks and verify the identity the router forwards.