Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

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.

  • graphql
  • api-security
  • introspection
  • batching
On this page 16 sections
  1. ·Why GraphQL is a different target
  2. ·Prerequisites
  3. ·Lab setup
  4. ·Build the target
  5. 1Confirm the endpoint and that introspection is on
  6. 2Dump the full schema
  7. Locked: Read the schema for sensitive fields and mutations
  8. Locked: Authenticate as the test account
  9. Locked: Bypass object-level authorization through a predictable ID
  10. Locked: Bypass field-level authorization on an admin-only field
  11. Locked: Abuse batching and aliasing to multiply one request
  12. Locked: Trace a resolver argument into a backend query
  13. Locked: Detection and defence
  14. Locked: Check
  15. Locked: Clean-up
  16. 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 curl and jq use. You do not need prior GraphQL experience — Step 1 to Step 3 teach you to read a schema.

Lab setup

ItemPurpose
curlSends every GraphQL request as an HTTP POST
jqFilters and reads the JSON responses and the dumped schema
base64Decodes 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 /graphql endpoint that accepts a JSON POST and answers { __typename }.
  • Introspection switched on. The schema has the types Query, Mutation, User, Order, Product, Coupon and Node.
  • The mutations login, updateProfile, createOrder, setUserRole and redeemCoupon, and the query fields node, user, products and redeemCouponAttempt. User has the fields id, email, isAdmin and orders.
  • The account tester@example.com with the password Str0ngPass!23: a plain user with no special privilege. Use your own password and put it in the commands.
  • An admin user User:1 with the email admin@corp.local, and a few orders of other users, for example Order:12 with the total 412.00 (Steps 5 and 6).
  • Global IDs of the form base64("TypeName:numericId"), as the Relay pattern uses (Step 5).
  • A products field that takes a filter string, and a MongoDB database behind it, with one product that has internal set 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

1

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

2

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.

graphqlintrospection.graphql
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.json

Example 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.

Related