Skip to content

LearnWeb and API

GraphQL API authorization testing

Brief

A GraphQL schema offers many paths to the same object, and authorization written into one resolver protects only that path. The review uses two test accounts to ask for each object through every path the schema allows, then checks the limits that stop one request from carrying a hundred operations.

Stage
Escalation
Reviewed
On this page
  1. Check first
  2. Is introspection on in production?
  3. Does every path to an object check authorization?
  4. Are aliases, batching and depth limited?
  5. Does the server run only queries the app registered?
  6. The defender sees
  7. Done when
  8. Not covered
  9. Tools
  10. Reviewed

All commands

Situation
A GraphQL API, the schema from the client's repository or a test environment, and test accounts in two organizations plus a member and an admin in our own test organization, each owning test objects. Every query names our own test objects, mutations touch only objects we created, and the batching check repeats a harmless query about our own account; we never send repeated login, code or coupon attempts. Only the APIs the scope letter names are tested.
Goal
An authorization table per type: each path to it (root query, node, nested fields), the result for another organization's object and for a member asking for admin-only fields, and the state of introspection, batching, depth limits and persisted queries.
Outputs
Captured on 4 Nov 2026 against the Atarus Bench Web and API lab fixture, edition web-api-0.2, running on loopback, with one origin playing every host, renamed to the example domains and printed as https (the lab ran plain http). The fixture's GraphQL endpoint is a small hand-written subset, so error wording is its own.

Check first

  • The GraphQL endpoints, and whether a gateway federates several services behind one.
  • The schema, from the client's repository or a test environment, so production needs no guessing.
  • Test accounts in two organizations, plus a member and an admin in our own, with test objects each one owns.
  • The limits the client believes it has: depth, cost, batching and rate.
  • Whether resolvers log the operation name, the user and each authorization denial.

Steps

Is introspection on in production?

curl -s https://api.example.com/graphql -H 'Content-Type: application/json' \
  -d '{"query":"{ __schema { types { name } } }"}' \
  | jq -r '.data.__schema.types[].name' | grep -v '^__' | head -n 5

Expected output

Query
Mutation
Order
AdminAuditEntry   # <- the full schema, admin types included, to a caller with no session
User

Introspection returns every type, field and argument. Turning it off is hygiene, not a control: field suggestions in error messages and the client's own JavaScript give the names away too, so we report it as low on its own and use the schema to drive the steps below.

Negative result. An error refusing introspection without a session, with field suggestions off.

Fix. Turn off introspection and field suggestions in production for unauthenticated callers, and publish the schema to the client's own developers another way.

Does every path to an object check authorization?

curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" \
  -H 'Content-Type: application/json' -d '{"query":"{ order(id: \"ord_test_b_0042\") { id total } }"}'

Expected output

{"errors":[{"message":"Not authorized","path":["order"]}],"data":{"order":null}}   # <- the baseline: the order query checks ownership
curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"query":"{ node(id: \"T3JkZXI6b3JkX3Rlc3RfYl8wMDQy\") { ... on Order { id total customer { email } } } }"}'

Expected output

{"data":{"node":{"id":"T3JkZXI6b3JkX3Rlc3RfYl8wMDQy","total":"120.00","customer":{"email":"tester-b@test.example"}}}}   # <- the same order through node, with tester-b's email

ord_test_b_0042 belongs to tester-b in the other test organization, and the node id is the base64 of Order:ord_test_b_0042. The root order query checks ownership; node loads the object by id and returns it without the same check. The same gap appears through nested fields, such as an order reached from a shared product. We repeat this for each type that holds tenant data and for admin-only fields and mutations, sent as our member account against objects in our own test organization.

Negative result. Every path returns an authorization error or null for another organization's object, and admin-only fields and mutations fail for the member.

Fix. Check authorization where each object is loaded, in the business layer every resolver calls, so node, root queries and nested fields share one rule. Deny new fields by default until a rule is attached.

Are aliases, batching and depth limited?

q=$(for i in $(seq 1 50); do printf 'a%d: me { id } ' "$i"; done)
curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" \
  -H 'Content-Type: application/json' -d "{\"query\":\"{ $q }\"}" | jq '.data | length'
curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" \
  -H 'Content-Type: application/json' -d '[{"query":"{ me { id } }"},{"query":"{ me { id } }"}]' | jq 'length'
deep='{ me { organization { members { organization { members { organization { members { id } } } } } } } }'
curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" \
  -H 'Content-Type: application/json' -d "$(jq -n --arg q "$deep" '{query: $q}')" | jq -c '.errors // "accepted"'

Expected output

50   # <- fifty operations in one request, counted once by a per-request rate limit
2
"accepted"   # <- a deeply nested query with no depth or cost error

Aliases and arrays let one HTTP request carry many operations, so a rate limit that counts requests does not count them. That matters for login, one-time code and coupon mutations, which we report from this result rather than test. Depth multiplies resolver work; our test organization has four members, so the query stays small here, but the same shape on real data does not.

Negative result. The alias request rejected or each alias counted against the limit, array batching off or capped, and the deep query refused with a depth or cost error.

Fix. Add query cost analysis with a maximum depth and complexity, count aliases and batched operations individually against rate limits, turn off array batching unless the client app needs it, and rate-limit sensitive mutations per account.

Does the server run only queries the app registered?

curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" -H 'Content-Type: application/json' \
  -d '{"extensions":{"persistedQuery":{"version":1,"sha256Hash":"0000000000000000000000000000000000000000000000000000000000000000"}}}' \
  | jq -c '.errors[0].message'
curl -s https://api.example.com/graphql -H "Authorization: Bearer $TESTER_A_TOKEN" -H 'Content-Type: application/json' \
  -d '{"query":"{ me { id createdAt } }"}' | jq -c '.data'

Expected output

"PersistedQueryNotFound"
{"me":{"id":"u_test_a","createdAt":"2026-10-27T10:02:11Z"}}   # <- a query the app never sends still runs

The first answer shows automatic persisted queries are on. That is a cache: the client may send a hash instead of the text, but any text is still accepted, as the second request shows. A safelist is different: the server runs only operations registered at build time and refuses everything else, which removes most of the surface above for first-party clients.

Negative result. The free-form query refused with an error naming the safelist.

Fix. For APIs that serve only the client's own apps, register operations at build time and refuse anything else in production. Keep authorization in the resolvers anyway, because a registered query still takes any id.

The defender sees

GraphQL usually answers 200 even when it refuses, so an access log shows a stream of identical POST /graphql 200 lines and status codes say nothing; the content does. The server needs to log the operation name or hash, the user and each authorization denial by field. Then the baseline denial for tester-a on ord_test_b_0042, followed by a successful node lookup of the same object, is a pattern an alert can catch, as are introspection without a session and a request with fifty aliases. If the logs hold only status codes, that is the finding, and the web app first hour lists the other routes worth the same logging.

Done when

Introspection is checked with and without a session, every type that holds tenant data is requested through each path with tester-a against tester-b's objects, admin-only fields and mutations are tried as a member, and the alias, array batching, depth and persisted query results are recorded.

Not covered

Injection through arguments, denial of service beyond one bounded depth query, subscriptions over WebSocket, and REST object checks (see IDOR testing).