appsec.fyi

GraphQL — A Practical Guide

A curated AppSec resource library covering XSS, SQLi, SSRF, IDOR, RCE, XXE, OSINT, and more.

GraphQL: A Practical Guide

Curated and synthesized by . Last updated 2026-08-01. Synthesized from 109 of 109 curated resources. Browse all 109 GraphQL resources →

The GraphQL Attack Surface

GraphQL, while a powerful and flexible query language for APIs, introduces a unique attack surface that deviates from traditional RESTful architectures. Its core principle of allowing clients to request precisely the data they need, often through a single endpoint, creates opportunities for sophisticated attacks if not properly secured.

The flexibility of GraphQL stems from its schema-driven nature, where clients construct queries based on a predefined schema. This schema defines the available types, fields, queries, and mutations. Unlike REST, where functionality is distributed across multiple endpoints, GraphQL centralizes these operations, making the single endpoint a critical point of interaction and potential vulnerability.

The adoption of GraphQL by major platforms like Facebook, GitHub, and Twitter underscores its utility, but also highlights the importance of understanding its security implications. As adoption grows, so does the focus of threat actors on exploiting its inherent characteristics.

Core Mechanics and Vulnerability Vectors

GraphQL's power lies in its ability to provide fine-grained data fetching. However, this same flexibility can be exploited. The primary security concerns revolve around how GraphQL endpoints are implemented and configured.

Introspection Abuse

GraphQL's introspection system allows clients to query the schema itself, revealing the API's structure, types, fields, and relationships. While beneficial for developers during development and for tooling like GraphiQL, leaving introspection enabled in production environments can be a significant security risk. Attackers can use this to enumerate the entire API surface, identify sensitive fields, and craft targeted attacks.

A basic introspection query:

{

__schema { queryType { fields { name } } } }

This query can reveal the names of available queries [1]. When introspection is disabled, attackers can sometimes infer schema details through field suggestions in error messages or by analyzing client-side JavaScript [2][3].

Authorization and Access Control Flaws

A fundamental challenge in GraphQL is the enforcement of authorization at a granular level. While authentication might verify a user's identity, authorization determines what actions that user is permitted to perform. GraphQL's flexible query structure can make implementing robust role-based access control (RBAC) more complex than in REST APIs [4].

Broken Object-Level Authorization (BOLA) is a common issue where an application fails to validate a user's permissions for a specific object or record. This can occur when predictable identifiers are used without sufficient backend validation [5][6]. For instance, an attacker might increment an object ID in a query to access data belonging to another user [7][8][9].

Similarly, Broken Function-Level Authorization can allow unauthorized users to execute specific queries or mutations. This often results from insufficient checks within resolvers or business logic [10][11].

Denial of Service (DoS) and Resource Exhaustion

GraphQL's ability to construct complex, nested queries can be exploited to cause Denial of Service (DoS) or resource exhaustion. Unlike REST, where each request has a fixed cost, GraphQL allows clients to build queries of arbitrary complexity. This can lead to attackers crafting queries that require disproportionate computation from the server.

Query Depth and Recursion

Deeply nested queries can force the server to resolve multiple levels of related objects, leading to exponential increases in computational load. Without limits on query depth, an attacker can craft a query that recursively traverses relationships, consuming excessive CPU and memory [12][13][2][14][15].

An example of a deep recursion query:

query DDoS {

searchGroups(name: "", limit: 1000000) { users { groups { users { groups { users { id } } } } } } }

This query can lead to millions of identifiers being returned, potentially overwhelming the server [13].

Batching Attacks and Alias Overloading

GraphQL supports query batching, allowing multiple queries or mutations within a single HTTP request. This can be used to bypass rate limiting, as the server might count only a single request rather than the individual operations within it [16][17][18][19][14][20][1][3][21].

Similarly, alias overloading allows an attacker to repeat costly operations within a single request by assigning different aliases to them. This can amplify the server's workload without being detected by basic rate limiting [22][17][23][4][14].

A mutation batching attack payload:

mutation {

login(username: "Tom", password: "password1") second: login(username: "Tom", password: "password2") third: login(username: "Tom", password: "password3") }

This allows for multiple login attempts in a single request [17].

Field Duplication and Complexity Bombs

Field duplication, where the same field is requested multiple times within a single query, can also increase server load. While some implementations might de-duplicate fields in the response, the server still expends resources processing the duplicate requests [18][19][14].

Complexity bomb queries exploit the schema to craft queries that appear simple but require significant backend computation. These often target specific implementations and require analysis of the schema to construct effectively [4].

Injection Vulnerabilities

Like any API, GraphQL endpoints are susceptible to injection attacks. Since GraphQL queries often involve passing arguments to backend data sources, unsanitized input can lead to various injection types.

SQL and NoSQL Injection

When GraphQL arguments are directly concatenated into database queries without proper sanitization or parameterization, SQL or NoSQL injection vulnerabilities can occur. This allows attackers to execute arbitrary database commands, potentially leading to data exfiltration or modification [24][25][26][27][18][19][14][28][29].

A GraphQL query attempting SQL injection:

query {

user(id: "' OR '1'='1") { name email } }

This query could return all users if the input is not properly handled [28].

Server-Side Request Forgery (SSRF)

SSRF vulnerabilities can arise when GraphQL queries accept URLs as arguments. Attackers can craft queries with malicious URLs pointing to internal network resources or cloud metadata endpoints, potentially leading to unauthorized access or credential exposure [10][2][18][14].

Operator Injection (NoSQL)

Even with relational databases, ORMs like Prisma can be vulnerable to operator injection if they support string-based query operators that are not properly validated. An attacker might manipulate these operators to alter query logic, leading to unintended data exposure [30].

Cross-Site Request Forgery (CSRF)

GraphQL APIs, particularly those relying on cookie-based authentication and exposed via a single, predictable endpoint, can be vulnerable to CSRF. Malicious websites can trick authenticated users' browsers into submitting unintended GraphQL mutations, leading to unauthorized actions [31][32][33][4][34][35][36][37].

A conceptual CSRF exploit targeting a GraphQL endpoint:

// Attacker's site

window.open("https://target.com/embedded_apollo_page", "_blank");

// After a delay, send a malicious message setTimeout(() => { window.postMessage({ type: "graphql_query", query: "mutation { updateUserProfile(userId: \"123\", banned: true) }", }, "https://target.com"); }, 2000);

This could trigger a profile update for an unsuspecting user [31].

Notable Exploitation Techniques

Understanding the common attack vectors is crucial. Many vulnerabilities exploit the inherent flexibility and default configurations of GraphQL.

Schema Enumeration and Reconnaissance

The first step in many GraphQL attacks is reconnaissance. Introspection queries are the primary tool for this, allowing attackers to map out the API's structure. Even without direct introspection, attackers can use tools like Clairvoyance to infer schema details from error messages and field suggestions [38][33][2][1][39][3].

Broken Object-Level Authorization (BOLA)

A critical vulnerability where an attacker can access or manipulate objects they are not authorized for. This often happens when predictable IDs are exposed and not properly validated at the resolver level.

"An AI agent autonomously read JavaScript, minted a session, discovered the API schema, identified an authorization gap, and confirmed mass data access to a major airline’s booking database, all within 15 minutes, with zero human guidance." [5][6]

User Enumeration and Information Disclosure

Vulnerabilities in GitLab's GraphQL API allowed unauthenticated attackers to enumerate usernames, names, and email addresses. This information can be used for further attacks like credential stuffing or targeted phishing [40]. Similarly, GraphQL can be abused to disclose sensitive data through various means, including IDORs and introspection [8][41][42].

Denial of Service via Malicious Queries

Specific query structures, such as deeply nested queries, queries with excessive aliases, or complex fragment expansions, can lead to DoS conditions. Tools like graphql-depth-limit and query complexity analysis can help mitigate these risks [43][44][45][46][13][2][14].

Authentication Bypass

Improper access control within GraphQL APIs can lead to authentication bypass, allowing unauthorized users to gain administrative privileges or access sensitive functionality. This often stems from weak validation of user input or session management issues within resolvers [11][47][9].

Detection and Prevention Strategies

Securing a GraphQL API requires a multi-layered approach, addressing vulnerabilities at the schema design, implementation, and runtime levels.

Schema Design and Validation

Disable Introspection in Production: Unless there's a specific, controlled use case, introspection should be disabled in production environments to limit the attack surface [27][48][49][50][14][1][51][15].

Input Validation and Sanitization: Rigorous validation and sanitization of all query arguments and inputs are critical to prevent injection attacks. This includes using allowlists, custom validators, and parameterized queries [27][18][28][29][52].

Field-Level Authorization: Implement authorization checks at the resolver level for every query and mutation. This ensures that users can only access data and perform operations for which they have explicit permissions [27][53][45][54][4][9][28].

Runtime Protections

Query Depth and Complexity Limiting: Enforce limits on query depth, complexity, or resource cost to prevent DoS attacks. Libraries like graphql-depth-limit or custom complexity analysis tools can be employed [12][45][46][13][2][14][29].

Rate Limiting: Implement rate limiting per user, IP address, or other identifiers to throttle abusive request patterns. This is especially important for sensitive mutations or queries [16][45][46][4][14].

Batching and Aliasing Restrictions: Configure servers to limit the number of queries allowed in a batch or to restrict the use of aliases for expensive operations [22][16][17][23][18][4][14].

CSRF Protection: Ensure GraphQL endpoints only accept POST requests with application/json content types, and consider implementing token-based CSRF protection mechanisms if necessary [32][51][34][35].

Secure Error Handling: Avoid verbose error messages in production that could leak sensitive information about the schema or backend systems [18][4][14][15].

Development Lifecycle Integration

Secure Coding Practices: Train developers on GraphQL-specific security vulnerabilities and secure coding practices. Emphasize the importance of proper input validation and authorization checks within resolvers [11][55][52].

Security Testing: Integrate automated security testing into the CI/CD pipeline. Tools that can dynamically test GraphQL APIs, identify vulnerabilities, and provide remediation guidance are crucial for continuous security [56][57][58][28].

Tooling for GraphQL Security

A variety of tools exist to aid in the discovery, analysis, and exploitation of GraphQL vulnerabilities.

Recent Developments and Trends

The threat landscape for GraphQL continues to evolve. Recent developments include:

Where to Go Deeper

For those looking to further enhance their understanding and skills in GraphQL security, the following resources are invaluable:

Sources cited in this guide

  1. Hacking GraphQL Endpoints in Bug Bounty Programs | YesWeHack — yeswehack.com
  2. GraphQL Security Testing: Introspection Abuse, Injection, and DoS — redteamworldwide.com
  3. https://blog.assetnote.io/2021/08/29/exploiting-graphql/ — blog.assetnote.io
  4. GraphQL API Security Risks Every Developer Should Know — wiz.io
  5. The Red Agent POV: Exploiting Broken Object-Level Authorization in an Airline GraphQL API — wiz.io
  6. The Red Agent POV: Exploiting Broken Object-Level Authorization in an Airline GraphQL API — wiz.io
  7. IDOR Vulnerability In GraphQL Api On inmobi.com — 1mirabbas.medium.com
  8. GraphQL IDOR leads to information disclosure (Eshan Singh) — medium.com
  9. GraphQL Security: How I Found and Exploited Critical IDOR and Authorization Bypass — infosecwriteups.com
  10. What Is API Security? — paloaltonetworks.com
  11. Exploiting Broken Authentication Control in GraphQL — praetorian.com
  12. Exploiting GraphQL Query Depth — checkmarx.com
  13. Cyclic Queries and Depth Limiting (Escape) — escape.tech
  14. GraphQL Security: 7 Common Vulnerabilities and Mitigations — tyk.io
  15. GraphQL Security from a Pentester's Perspective | AFINE — afine.com
  16. Didn't Notice Your Rate Limiting: GraphQL Batching Attack — checkmarx.com
  17. Avoid GraphQL Denial-of-Service Attacks through Batching and Aliasing — escape.tech
  18. Hacking (and Securing) GraphQL — blog.arcjet.com
  19. GraphQL Attacks and Vulnerabilities — beaglesecurity.com
  20. GraphQL API Vulnerabilities, Common Attacks & Security Tips — vaadata.com
  21. swisskyrepo/GraphQLmap: GraphQLmap is a scripting engine to interact with a — github.com
  22. How GraphQL Mutation Aliasing Led to a $12,500 DoS Bug in HackerOne’s Account Recovery Flow — infosecwriteups.com
  23. DoS via Mutation Aliasing in GraphQL — HackerOne Disclosure — redpacketsecurity.com
  24. Hasura GraphQL 1.3.3 Local File Read via SQL Injection — vulncheck.com
  25. Discovering GraphQL endpoints and SQLi vulnerabilities — medium.com
  26. HackerOne Report #435066: SQL injection in GraphQL endpoint — hackerone.com
  27. GraphQL Security: 9 Best Practices to Protect Your API (Escape) — escape.tech
  28. GraphQL Security Testing Guide (2026) — levo.ai
  29. GraphQL Cheat Sheet | OWASP — cheatsheetseries.owasp.org
  30. Prisma and PostgreSQL vulnerable to NoSQL injection? (Aikido) — aikido.dev
  31. CVE-2025-59845: CSRF Vulnerability in Apollo Studio Embeddable Explorer and Sandbox — ameeba.com
  32. Exploiting CSRF in GraphQL Applications — fdzdev.medium.com
  33. Exploiting GraphQL (Assetnote Research) — assetnote.io
  34. Facebook GraphQL CSRF – These aren't the access_tokens you're looking for — philippeharewood.com
  35. [TOKOPEDIA] SITE-WIDE CSRF THROUGH GRAPHQL REQUEST — rafiem.github.io
  36. Facebook GraphQL CSRF – These aren't the access_tokens you're looking for — philippeharewood.com
  37. [TOKOPEDIA] SITE-WIDE CSRF THROUGH GRAPHQL REQUEST — rafiem.github.io
  38. Ghost Accounts Abuse GitHub API in Mass Recon Campaign — securityweek.com
  39. Escape-Technologies/awesome-graphql-security: A curated list of awesome GraphQL Security frameworks, libraries, software and resources — github.com
  40. CVE-2021-4191: GitLab GraphQL API User Enumeration (FIXED) — rapid7.com
  41. GraphQL introspection leads to sensitive data disclosure. — medium.com
  42. GraphQL Introspection leads to Sensitive Data Disclosure. — medium.com
  43. CVE-2025-31496: GraphQL Query Vulnerability in Apollo Compiler Leading to DoS — ameeba.com
  44. Apollo Router Query Planner Excessive Resource Consumption via Named Fragment Expansion (CVE-2025-32034) — github.com
  45. 9 Ways To Secure your GraphQL API - Apollo Checklist — apollographql.com
  46. Securing GraphQL API endpoints using rate limits and depth limits (LogRocket) — blog.logrocket.com
  47. How a GraphQL Bug Resulted in Authentication Bypass — hackerone.com
  48. Exploiting GraphQL for Penetration Testing (Raxis) — raxis.com
  49. Abusing GraphQL Introspection: A Gateway for Recon and Exploitation — infosecwriteups.com
  50. GraphQL API Vulnerabilities - PortSwigger — portswigger.net
  51. GraphQL | HackTricks — book.hacktricks.xyz
  52. GraphQL - Security Overview and Testing Tips · Doyensec's Blog — blog.doyensec.com
  53. Authorization in GraphQL (Apollo) — apollographql.com
  54. Apollo Authentication and Authorization Docs — apollographql.com
  55. The Complete GraphQL Security Guide: Fixing the 13 Most Common Vulnerabilities — wundergraph.com
  56. How Escape DAST helped Sigma Computing achieve complete GraphQL API endpoint coverage — securityboulevard.com
  57. Best GraphQL security tools in 2026: An in-depth guide including business logic and enterprise coverage — securityboulevard.com
  58. GraphQL API Vulnerabilities Learning Path — PortSwigger — portswigger.net
  59. PayloadsAllTheThings — GraphQL Injection — github.com
  60. InQL: Advanced GraphQL Security Testing Burp Extension — github.com
  61. https://github.com/gsmith257-cyber/GraphCrawler — github.com
  62. Slides: GraphQL Hacking — rashahacks.com
  63. Teycir/BurpAPISecuritySuite: Burp Suite extension for API security testing with 15 attack types, 108+ payloads, intelligent fuzzing, BOLA/IDOR detection, AI integration, and automated reconnaissance. Supports REST/GraphQL/SOAP APIs with Nuclei, Turbo Intruder, and external tool integration. OWASP API Top 10 coverage. — github.com
  64. br3akp0int/GQLParser: A repository for GraphQL Extension for Burp Suite — github.com
  65. doyensec/graph-ql: GraphQL Security Research Material — github.com
  66. doyensec/graph-ql: GraphQL Security Research Material — github.com
  67. Exploiting GraphQL — blog.assetnote.io
  68. Damn Vulnerable GraphQL Application — github.com
  69. Best AI DAST tools in 2026: ranked compared and reviewed for enterprise security teams — securityboulevard.com
  70. DarkMoon AI-Powered Autonomous Penetration Testing Platform With 50 Tools — cybersecuritynews.com
  71. TanStack npm Packages Hit by Mini Shai-Hulud — snyk.io
  72. API Threat Research: GraphQL Authorization Flaws in a FinTech Platform — salt.security
  73. Exploiting Broken Access Control on GraphQL — vaadata.com
  74. Enforcing GraphQL security best practices with GraphOS — apollographql.com
  75. GraphQL Introspection Security: Lessons from the Parse Server Vulnerability — escape.tech
  76. Exploiting GraphQL Vulnerabilities: Misconfig to Data Leaks — dev.to
  77. Mastering the Realm of GraphQL Exploitation — medium.com
📚 This guide is synthesized from the full text of resources curated in the GraphQL library, and refreshed as new material is added.