← All tracks
Server-SideGraphQL10 labsAdvanced7h practice

GraphQL: One Endpoint, Many Doors

Authorization must live on every field, not on the URL.

“One endpoint. Many doors. The schema told the attacker which ones were unlocked.”

CWE-639OWASP API Security API1:2023OWASP ASVS 4.1.3
The mental model
GraphQL exposes a typed graph. The client chooses the shape of the response, so the server must authorize every node and field, not just the entry point.

Introspection reveals types and fields. A resolver accepts an ID and returns data without checking ownership. The attacker queries another user's object and requests an admin-only field.

We secure the endpoint and forget the graph.

Threat model

What is actually at stake?

Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.

Assets

  • User and tenant objects
  • Admin-only fields
  • Mutations and bulk operations
  • Schema metadata and internal types

Actors

  • Authenticated user with a normal role
  • Attacker using introspection or field guessing
  • Malicious client sending batched or deeply nested queries

Trust boundaries

  • Query field to resolver policy
  • Parent object to child object
  • Alias to rate limit
  • Introspection to production schema
  • Mutation input to privileged field

Abuse cases

  • Query user(id) for another tenant
  • Request an admin-only field on a visible object
  • Use aliases to bypass a per-query limit
  • Chain nested objects to reach private data
  • Abuse verbose errors to infer schema
PrerequisitesGraphQL schema, queries and resolversIntrospection and fragmentsObject-level authorization
Request anatomy

Follow the decision, not the payload

Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.

  1. 01

    Parse

    The server parses a query document with fields, aliases, fragments and variables.

  2. 02

    Validate

    The schema validates shape, but validation is not authorization.

  3. 03

    Resolve

    Each field calls a resolver with a parent object and context.

  4. 04

    Authorize

    Every resolver must check whether the subject may read this field on this object.

  5. 05

    Return

    The response may include partial data and detailed errors, creating new inference channels.

Case study

The field that skipped the policy

Composite case study from public GraphQL disclosures
Context

A composite case based on recurring GraphQL disclosures: the top-level query checked tenant access, but a nested field resolver returned a sensitive relation without its own check.

Discovery

A tester queried their own order, then added a nested customer field. The parent resolver authorized the order, but the child resolver trusted the parent and returned another tenant's customer record.

Impact

Cross-tenant data exposure through a single query. The same pattern affected mutations where an input field reached a privileged relationship.

Root cause

Authorization was applied at the route or top-level resolver instead of every field and mutation that could cross an object boundary.

Fix

Enforce policy in every resolver or a shared authorization directive, scope queries by tenant, disable or protect introspection in production, and add depth and alias limits.

Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.

Attacker lens

A repeatable testing sequence

  1. Run an introspection query and map types, fields and arguments.
  2. Query your own object, then change the ID.
  3. Request hidden or admin-only fields.
  4. Use aliases, fragments and batching to test many paths at once.

Where smart people get fooled

  • One endpoint does not mean one authorization check.
  • The UI hides a field; the schema still exposes it.
  • Introspection is often enabled in production.
Detection engineering

What would the logs show?

A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.

  • Introspection queries in production
  • Many aliases or deeply nested selections from one client
  • Queries that request fields outside the caller's role
  • Repeated errors naming internal types or resolvers
  • A single operation touching multiple tenants
Starter query
index=web sourcetype=graphql | eval risky=if(match(query,"(__schema|__type|aliases|tenantId)"),1,0) | where risky=1 | stats count values(operation_name) by user_id, clientip | where count > 10
The defender's move

Fix the decision, then prove it stays fixed

  • Enforce field-level and object-level authorization in resolvers.
  • Disable introspection in production and limit query depth/cost.
  • Use persisted queries and rate limits.
Vulnerable patterntypescript
order: (_, { id }, ctx) => db.order.findUnique({ where: { id } })
Safer patterntypescript
order: async (_, { id }, ctx) => {
  const order = await db.order.findFirst({ where: { id, tenantId: ctx.user.tenantId } });
  if (!order) throw new GraphQLError("Not found");
  return order;
}
// child resolvers also receive ctx and enforce field-level policy

Treat every resolver as an API endpoint. Apply tenant and role checks in the resolver or a shared directive, not only at the HTTP route.

Regression tests a reviewer would ask for

Cross-tenant object

GivenTwo tenants each own an order

WhenTenant A queries Tenant B's order ID

ThenThe resolver returns not found or forbidden

Nested field

GivenA visible parent object has a sensitive child relation

WhenA normal user selects the child field

ThenThe child resolver enforces its own policy

Mutation input

GivenA mutation accepts an input object

WhenThe input includes tenantId or role

ThenThe schema rejects or ignores privileged fields

Alias abuse

GivenA client sends many aliases in one operation

WhenThe query count exceeds the limit

ThenThe server rejects the operation before resolving fields

False positives

What this finding is not

Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.

  • Introspection is enabled: this is a hardening issue, not automatically a data breach; test field-level authorization next.
  • A query returns an error for another user's ID: test nested fields, aliases and mutations before concluding the schema is safe.
  • A field is hidden from the docs: the schema may still expose it, and field names can be guessed.
  • The response omits a field: partial errors may reveal whether it exists or whether authorization failed.
Working vocabulary

Terms you should be able to use precisely

Resolver
The function that returns data for a GraphQL field.
Introspection
A GraphQL query that returns the schema's types and fields.
Alias
A client-chosen response key that lets one operation request the same field multiple times.
Fragment
A reusable selection set shared across queries.
Field-level authorization
A policy decision applied to each field, not only the top-level query.
Query depth limit
A control that rejects excessively nested operations to limit cost and abuse.
Interview drill

Answer these without reciting a payload

Why is introspection not the main GraphQL security problem?

It reveals the schema, but the real risk is missing field-level authorization. Even without introspection, field names can be guessed or learned from clients.

Where should authorization live in GraphQL?

In every resolver or a shared authorization layer/directive that receives the subject, object and field context. Top-level route checks are not sufficient.

How do aliases create abuse?

A single operation can request the same expensive field many times with different aliases, bypassing naive per-query rate limits.

Knowledge check

Can you separate the mechanism from the payload?

Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.

4 questions
01A user can query their own order but sees another tenant's customer through a nested field. What failed?
02Which control limits alias-based abuse?
03Is disabling introspection a complete fix?
04How should tenant scope be applied?
الخلاصة الموسّعة
لماذا هذا مهم؟

GraphQL يبدو واجهة واحدة، لكنه في الحقيقة عشرات نقاط الوصول: كل حقل وكل resolver قرار صلاحية مستقل.

الخطأ الشائع هو حماية الاستعلام الأعلى ثم ترك الحقول المتداخلة تثق بالأب. طبّق السياسة في كل resolver، أو عبر توجيه مركزي، وقيّد الاستعلامات بالعمق والـaliases والتكلفة. تعطيل introspection مجرد تحصين، وليس بديلًا عن التحقق من الصلاحيات.

Which resolver checked ownership for this field?