Practice library / Web attacks
Lab · Medium · 2 hoursFree account
Attacking GraphQL
Introspection, BOLA/BFLA on resolvers, batching abuse, and resolver-level injection against a GraphQL API.
On this page 16 sections
- ·Why GraphQL is a different target
- ·Prerequisites
- ·Lab setup
- ·Build the target
- 1Confirm the endpoint and that introspection is on
- 2Dump the full schema
- Locked: Read the schema for sensitive fields and mutations
- Locked: Authenticate as the test account
- Locked: Bypass object-level authorization through a predictable ID
- Locked: Bypass field-level authorization on an admin-only field
- Locked: Abuse batching and aliasing to multiply one request
- Locked: Trace a resolver argument into a backend query
- Locked: Detection and defence
- Locked: Check
- Locked: Clean-up
- Locked: Command reference
GraphQL replaces many URLs with one endpoint and lets the client choose which fields to read. That flexibility moves the authorisation surface from the route to the resolver — and a missing check at that layer touches every query that uses the field. The engineer dumps a schema with introspection, breaks object- and field-level authorisation, abuses query batching, and traces a resolver argument into a backend injection.
Lab Objectives
- Confirm a GraphQL endpoint and pull its full schema with an introspection query
- Read a dumped schema to find sensitive types, fields and mutations
- Bypass object-level authorization through a predictable global ID
- Bypass field-level authorization on a field a resolver forgot to guard
- Abuse query batching to send many sensitive operations in one HTTP request
- Trace a resolver argument into a backend query to find an injection point
Why GraphQL is a different target
A REST API exposes many URLs, each with its own authorization check. A GraphQL API exposes one URL and lets the caller choose which fields and which nested objects to read in a single request. That flexibility is the attack surface. A missing check on one field, one resolver, or one argument reaches every query that touches it. The schema itself tells you where to look, if introspection is on.
Prerequisites
- Finish API & Web Service Attacks first. Broken object-level authorization (BOLA) and broken function-level authorization (BFLA) work the same way here; this lab applies them to resolvers instead of REST routes.
- Read NoSQL Injection before Step 8. The resolver injection in this lab lands in the same kind of backend query.
- Comfort with JSON and basic
curlandjquse. You do not need prior GraphQL experience — Step 1 to Step 3 teach you to read a schema.
Lab setup
| Item | Purpose |
|---|---|
curl | Sends every GraphQL request as an HTTP POST |
jq | Filters and reads the JSON responses and the dumped schema |
base64 | Decodes and re-encodes the global object IDs used in Step 5 |
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against a GraphQL API that you build. 10.0.14.30:4000/graphql and the name ShopGraph are the example address and name of this lab. Replace the address in every command with your own.
Your GraphQL API must have these parts:
- One
/graphqlendpoint that accepts a JSON POST and answers{ __typename }. - Introspection switched on. The schema has the types
Query,Mutation,User,Order,Product,CouponandNode. - The mutations
login,updateProfile,createOrder,setUserRoleandredeemCoupon, and the query fieldsnode,user,productsandredeemCouponAttempt.Userhas the fieldsid,email,isAdminandorders. - The account
tester@example.comwith the passwordStr0ngPass!23: a plain user with no special privilege. Use your own password and put it in the commands. - An admin user
User:1with the emailadmin@corp.local, and a few orders of other users, for exampleOrder:12with the total412.00(Steps 5 and 6). - Global IDs of the form
base64("TypeName:numericId"), as the Relay pattern uses (Step 5). - A
productsfield that takes afilterstring, and a MongoDB database behind it, with one product that hasinternalset to true (Step 8).
No public training target fits this lab, so build a small API of your own. A Node.js GraphQL server with a MongoDB container, both on your own machine, is enough. Take a snapshot or note the container state before Step 1, so that you can go back to it.
Legal note. Run every command in this lab only against a target that you own or have written permission to test, here 10.0.14.30. Introspection, batching and resolver probing against a server you do not own or have written permission to test is unauthorized access in most countries.
Step 1: Confirm the endpoint and that introspection is on
Send a minimal query and read the response shape
A GraphQL endpoint answers a POST of {"query": "..."} with Content-Type: application/json, and returns a data key (and sometimes errors). Confirm that shape first, then ask the server to describe itself.
# Minimal query every GraphQL server understands
curl -s -X POST http://10.0.14.30:4000/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ __typename }"}'
# Ask whether introspection is enabled
curl -s -X POST http://10.0.14.30:4000/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ __schema { queryType { name } } } "}'Example output:
{"data":{"__typename":"Query"}}
{"data":{"__schema":{"queryType":{"name":"Query"}}}}The second response proves introspection is enabled. Many production APIs disable it; if yours returns an error here, the server likely blocks the __schema field, and you would move to schema guessing from client code or error messages instead — out of scope for this lab.
Step 2: Dump the full schema
Send the standard introspection query and save the result
The GraphQL specification defines one introspection query that every compliant server understands. Save it to a file, wrap it as JSON with jq, and send it.
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
types {
kind
name
fields(includeDeprecated: true) {
name
args { name type { kind name ofType { kind name } } }
type { kind name ofType { kind name } }
}
}
}
}jq -n --rawfile query introspection.graphql '{query: $query}' > payload.json
curl -s -X POST http://10.0.14.30:4000/graphql \
-H "Content-Type: application/json" \
--data @payload.json -o schema.json
jq '.data.__schema.types[].name' schema.jsonExample output:
"Query"
"Mutation"
"User"
"Order"
"Product"
"Coupon"
"Node"This is a simplified version of the standard introspection query defined in the GraphQL specification. This trimmed version asks only for names, kinds and argument types — enough to map the API without the much longer query that also pulls descriptions and nested type chains.
Sign in to continue
10 more sections are for signed-in members. It is free: sign in with Google.