CIDADAXSEC
← All topics
Practitioner

GraphQL API vulnerabilities

GraphQL vulnerabilities come from resolvers that skip access checks, hidden endpoints, repeated aliases, and queries that can be triggered cross-site.

Material

GraphQL replaces many REST endpoints with one endpoint that accepts a query shaped like a tree. Because the client dictates the response shape, a single endpoint can expose far more data than any screen shows.

How it works

The client posts a query or mutation as JSON to a single path, often /graphql or /api/graphql. The server resolves it against the schema and answers with JSON. The schema itself is usually reachable through introspection.

Access control therefore belongs in every resolver. A field that nobody links on the interface can still exist in the schema and still answer, because nothing stops a client from naming it directly.

http
POST /graphql HTTP/1.1
Host: lab.example
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9

{"query":"query { user(id: 1) { id email role password } }"}
javascript
const body = {
  query: `query {
    __schema {
      types { name kind fields { name type { name kind } } }
      mutationType { name }
    }
  }`
};

const res = await fetch('/graphql', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(body)
});

Attack shapes

  • Private fields exposed because the resolver returns them without checking the caller.
  • Hidden GraphQL endpoints living on other paths such as /graphql/console or /v1/graphql.
  • Rate limit bypass by repeating the same field under many aliases inside one request.
  • CSRF over GraphQL, where a query travels in a GET request that a tag on another page can trigger.
  • Cross-user leakage through batched queries that pull records belonging to other accounts.

Preventing it

  • Disable introspection in production, or restrict it to a trusted developer surface.
  • Authorize in every resolver, including nested fields and fields no screen currently uses.
  • Cap query depth, complexity, and the number of aliases per request.
  • Require CSRF protection and reject state-changing operations delivered over GET.
  • Normalize queries before counting them for rate limits, and batch id lookups through a single loader.
javascript
const aliasAbuse = `query {
  a: user(id: 1) { id email }
  b: user(id: 2) { id email }
  c: user(id: 3) { id email }
  d: user(id: 4) { id email }
  e: user(id: 5) { id email }
}`;
// satu permintaan HTTP, lima kali lookup field
Note: introspection is not the security boundary. Field level authorization and depth limits are what actually stop the abuse.

Labs in this topic

Labs run on a domain separate from this site, so a payload cannot reach your account session.

Labs for this category land in Phase 2. The material is readable now.

Challenges in this category

Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.