Access control vulnerabilities in GraphQL APIs

Nikita Stupin (Mail.ru)

Swiss Cyber Storm 2019 · Day 1 · Main

Overview

In this insightful talk from Swiss Cyber Storm, Nikita Stupin of Mail.ru delves into the critical area of access control vulnerabilities within GraphQL APIs. As GraphQL rapidly gains traction across the industry, adopted by technology giants like Facebook, GitHub, Shopify, and Twitter, understanding its unique security challenges becomes paramount. Stupin's research highlights that while GraphQL offers significant advantages over traditional REST APIs, its inherent flexibility introduces a new landscape for security vulnerabilities, with access control issues being the most prevalent and impactful.

Watch on YouTube

Visual summary for Access control vulnerabilities in GraphQL APIs by Nikita Stupin
Visual summary for Access control vulnerabilities in GraphQL APIs by Nikita Stupin

Key moments

  1. 1:10 Talk plan: What, how to analyze, attack surface, defense
  2. 2:30 GraphQL solves REST API over/under fetching problems
  3. 7:40 GraphQL Voyager: Visualizing API schema for easier analysis
  4. 10:00 Most common vulnerabilities: Access control issues
  5. 10:50 Unique vulnerability: "Broken edges" with missing access checks
  6. 13:50 Defense using GraphQL directives for granular access control
  7. 16:15 Future of GraphQL: Complementing or replacing REST APIs

Access control vulnerabilities in GraphQL APIs

Speakers: Nikita Stupin, Security Researcher, Mail.ru

Conference: Swiss Cyber Storm

YouTube: https://www.youtube.com/watch?v=bCfKqPnt_8Y

Overview

In this insightful talk from Swiss Cyber Storm, Nikita Stupin of Mail.ru delves into the critical area of access control vulnerabilities within GraphQL APIs. As GraphQL rapidly gains traction across the industry, adopted by technology giants like Facebook, GitHub, Shopify, and Twitter, understanding its unique security challenges becomes paramount. Stupin's research highlights that while GraphQL offers significant advantages over traditional REST APIs, its inherent flexibility introduces a new landscape for security vulnerabilities, with access control issues being the most prevalent and impactful.

The presentation provides a comprehensive guide for security professionals and developers, starting with a foundational understanding of GraphQL's architecture and common interaction patterns. Stupin then transitions into practical aspects, detailing the specific attack surfaces he's identified through real-world bug bounty research. He illustrates these points with examples of vulnerabilities he personally discovered, including a "broken edges" flaw that earned a $4,000 bounty, underscoring the financial and operational risks associated with insecure GraphQL implementations.

Ultimately, Stupin offers actionable defense mechanisms, advocating for robust access control strategies implemented through resolvers and GraphQL directives. His talk serves as a crucial wake-up call, emphasizing that while GraphQL streamlines data fetching and modification, its security cannot be an afterthought. By addressing these vulnerabilities proactively, organizations can harness the power of GraphQL without exposing themselves to undue risk.

Background

▶ Watch: Talk plan: What, how to analyze, attack surface, defense (1:10)

GraphQL emerged approximately four to five years prior to this talk as an open-source data query language for APIs, designed to address fundamental limitations encountered with traditional RESTful architectures. From a client-side perspective, GraphQL provides an efficient and flexible method to fetch and modify data from a server, serving as a powerful alternative to REST APIs rather than a database itself.

The primary problems GraphQL aims to solve in REST APIs are data overfetching and data underfetching. Data overfetching occurs when a client requests a specific piece of information (e.g., a user's name), but the API response includes a much larger dataset, such as the user's last name, number of repositories, user type, and ID. This unnecessary data transfer leads to increased network load and degraded application performance. Conversely, data underfetching happens when a client needs multiple distinct pieces of data, requiring several separate requests to different endpoints (e.g., one for organization names, another for repository descriptions). This again burdens the network and complicates client-side logic. GraphQL resolves these issues by allowing clients to specify exactly what data they need, no more and no less, in a single request, as demonstrated by an example query fetching a user's organizations and repositories.

On the server side, GraphQL typically acts as a layer between the client and a database. However, in real-world scenarios, it often serves as an aggregation layer, sitting in front of existing REST APIs, various microservices, or even different SQL and NoSQL databases. This architectural complexity means that security testing must extend beyond the GraphQL layer itself to encompass the underlying technologies it interacts with.

Interacting with GraphQL APIs primarily involves three types of requests. The most common is the Query, used exclusively for fetching data. To facilitate interaction and testing, tools like GraphiQL are invaluable. GraphiQL functions much like a web proxy's repeater, providing an interactive environment with syntax highlighting and formatting for crafting and executing GraphQL queries. While GraphQL queries can be intercepted in tools like Burp Suite due to their HTTP-based nature, they are represented as single strings, making complex nested queries cumbersome to analyze without specialized tools.

The second type of request is Mutation, which is employed when a client intends to modify, delete, or create data on the server. Mutations accept parameters, similar to how REST API POST requests do, making them susceptible to classic injection vulnerabilities, such as SQL injection, though GraphQL's strong typing can mitigate some of these risks. The third request type, Subscription, is designed for real-time, persistent connections between client and server, typically using WebSockets. This is particularly useful for applications requiring live updates, such as chat applications, where clients receive events as new data becomes available rather than continuously polling the server. While queries and mutations are ubiquitous, subscriptions are not present in every GraphQL API.

A cornerstone of GraphQL is its schema, which is a comprehensive description of the API's capabilities. This schema is typically a large JSON file, often thousands of lines long (e.g., 50,000 lines), detailing all available objects, their fields, and the connections between them, as well as what data can be modified or deleted. Manually parsing such a vast JSON file is impractical. This is where tools like GraphQL Voyager become indispensable. GraphQL Voyager takes the schema, often obtained via an introspection request, and visualizes it as an interactive graph. In this graph, objects are represented as nodes, and the relationships between them are depicted as edges. Introspection, by default, allows any client to send a special query to retrieve the entire schema. While this might sound alarming, it is primarily a development and auditing feature. For security auditors, GraphQL Voyager provides an immediate, comprehensible overview of the API's entire surface, which Stupin notes has been instrumental in discovering vulnerabilities.

Key Findings

▶ Watch: GraphQL Voyager: Visualizing API schema for easier analysis (7:40)

Nikita Stupin's research, corroborated by experiences from fellow bug bounty hunters and publicly disclosed reports on platforms like HackerOne, unequivocally points to access control vulnerabilities as the "most big problem" in GraphQL APIs. While other issues, such as injections, do exist, their prevalence is significantly lower due to GraphQL's inherent strong typing. This design feature ensures that parameters are validated against their expected types (e.g., an ID parameter expecting an integer will reject a string), thereby preventing many common injection attacks before they even reach the backend logic.

Despite strong typing, the complexity and flexibility of GraphQL often lead to developers overlooking critical access control checks. Many of these vulnerabilities are conceptually similar to those found in REST APIs, such as insecure direct object references (IDORs) or privilege escalation, but the methods and tools used to discover them differ.

However, Stupin identified a specific and unique category of GraphQL access control vulnerability he terms "broken edges." In GraphQL's graph model, objects are represented as nodes, and the relationships or connections between these objects are represented as edges. Developers frequently add additional data or attributes directly onto these edges. The "broken edges" vulnerability arises when developers implement access control checks on the nodes (the objects themselves) but fail to implement corresponding checks on the data associated with the edges connecting these nodes. This oversight can allow unauthorized users to access sensitive information or perform actions by traversing these unchecked connections.

Stupin highlighted the impact of such vulnerabilities, recounting how a "broken edges" flaw he discovered earned him a $4,000 bounty. Although the specifics of this particular report remain undisclosed due to company policies, he referenced a similar, publicly disclosed report that yielded a substantial $20,000 bounty, underscoring the critical nature and potential financial rewards for identifying these nuanced GraphQL vulnerabilities. His advice to auditors is clear: when reviewing a GraphQL API, "first look at the edges," as these often represent overlooked attack vectors where access control checks are absent or improperly implemented.

Technical Deep Dive

▶ Watch: Most common vulnerabilities: Access control issues (10:00)

The architectural flexibility of GraphQL, while a core strength, is also a primary contributor to its access control challenges. The GraphQL specification itself offers no prescriptive guidance on where or how to implement authentication and authorization. This freedom allows developers to place access control checks at various layers: on the frontend server, within the GraphQL layer itself, at the business logic layer, or even, in less common and potentially problematic scenarios, directly at the database layer. While this flexibility empowers developers, it also creates fertile ground for inconsistencies and errors, as different teams or individual developers might adopt disparate, and potentially insecure, approaches.

Despite this broad spectrum of options, Stupin advocates for two primary, secure, and convenient methods for implementing robust access control in GraphQL APIs: using resolvers or GraphQL directives.

Resolvers are arguably the most straightforward approach. In GraphQL, a resolver is an ordinary function responsible for fetching the data for a specific field in a query. For instance, a resolver for a name field might execute a SQL query to retrieve the name from a database. The simplicity of resolvers allows developers to embed access control checks directly within these functions. Before any data is fetched or returned, the resolver can perform necessary authorization checks—for example, verifying if the requesting user has permission to access a particular record or field. This method is intuitive and integrates seamlessly into existing codebases, making it a common choice for initial implementations.

The second recommended approach involves GraphQL directives. Directives are an intrinsic part of the GraphQL query language, allowing for metadata to be attached to fields or types. While GraphQL provides few default directives, developers can implement custom directives. These custom directives can then be used to specify granular access control rules. For example, a @hasRole(role: "ADMIN") directive could be applied to a specific field, ensuring that only users with the 'ADMIN' role can access that data. This offers a more granular level of control compared to resolvers, which typically operate at the object or field level. Directives can restrict access to not just an entire object, but to specific fields within that object, or even combinations of fields. Furthermore, directives are "native" to GraphQL, leading to cleaner code and API definitions. Stupin emphasizes that cleaner code generally leads to fewer vulnerabilities, as there are fewer opportunities for developers to introduce subtle mistakes in access control logic.

The ability to obtain a comprehensive understanding of a GraphQL API's structure is also a critical technical aspect for both developers and auditors. As mentioned, GraphQL APIs are by default introspectable, meaning any client can execute a special introspection query. This query retrieves the entire GraphQL schema, including all defined objects, their fields, the relationships (edges) between them, and information about which fields can be modified or deleted. While this exposure can be seen as a security concern in production environments if not properly managed, Stupin points out that it is an invaluable asset for security auditing. Tools like GraphQL Voyager leverage this introspection capability to transform the raw, often overwhelming, JSON schema into an easily navigable and visually intuitive graph. Even for large and complex APIs, such as the GitHub API, this visualization makes it significantly easier to understand the API's full attack surface and identify potential areas where access control might be weak or missing, particularly in the "edges" connecting different data nodes.

Demo / Proof of Concept

▶ Watch: Defense using GraphQL directives for granular access control (13:50)

While Nikita Stupin's talk did not include a live, step-by-step demonstration or a detailed, public proof of concept, he strongly validated his findings through references to real-world vulnerabilities and successful bug bounty engagements. He explicitly stated that he discovered "real-world vulnerabilities" during his research into GraphQL access control.

A key highlight was his personal discovery of a "broken edges" vulnerability, which resulted in a $4,000 bounty. Although the specifics of this particular vulnerability could not be disclosed due to the company's non-disclosure policies, its financial reward underscores the tangible impact of such flaws. Furthermore, Stupin referenced a similar, publicly disclosed "broken edges" vulnerability that garnered a substantial $20,000 bounty. These examples serve as concrete evidence of the existence and severity of GraphQL access control issues, particularly those unique to its graph-based structure. The speaker's practical experience in identifying and reporting these vulnerabilities reinforces the urgent need for robust security practices in GraphQL API development.

Defensive Implications

▶ Watch: Future of GraphQL: Complementing or replacing REST APIs (16:15)

Securing GraphQL APIs, particularly against access control vulnerabilities, requires a multi-faceted approach that leverages GraphQL's unique features while also adhering to general security best practices. Based on Stupin's findings, several key defensive implications emerge for developers and security professionals:

  1. Implement Robust Access Control at the Right Layers: Given that the GraphQL specification does not dictate where authentication and authorization should occur, developers must consciously choose and consistently apply these checks. Stupin highlights two highly effective methods:
  • Utilize Resolvers for Field-Level Checks: Embedding access control logic directly within resolver functions is a straightforward and effective way to ensure that only authorized users can fetch specific data fields. This means that before a resolver fetches data from a database or another service, it should perform explicit authorization checks.
  • Leverage GraphQL Directives for Granular Control: For more nuanced and declarative access control, custom GraphQL directives are ideal. Directives allow for granular permissions (e.g., @hasRole(role: "ADMIN")) to be attached directly to schema fields or types. This not only makes access rules explicit within the schema but also promotes cleaner, more maintainable code, reducing the likelihood of errors.
  1. Scrutinize "Edges" for Broken Access Control: Stupin's "broken edges" finding is a critical defensive insight. Developers must ensure that access control checks are not only applied to the primary data nodes (objects) but also to the data and relationships represented by the edges connecting these nodes. It's common for developers to overlook these connections, leading to unauthorized data disclosure or manipulation through seemingly innocuous relationships. Security testing should specifically target these edge cases.
  1. Harness Strong Typing to Mitigate Injections: GraphQL's strong typing is a powerful built-in defense against many common injection vulnerabilities. Developers should fully leverage this feature by strictly defining parameter types and relying on GraphQL's validation mechanisms. This significantly reduces the attack surface for SQL injection and similar flaws, as invalid input types are rejected before they reach the backend logic.
  1. Manage Introspection in Production Environments: While introspection queries are invaluable for development and auditing (as highlighted by tools like GraphQL Voyager), their availability in production environments should be carefully considered. Disabling introspection for unauthenticated users or restricting it to internal-only access can prevent adversaries from easily mapping the entire API schema, thus hindering their reconnaissance efforts. This is a common best practice, although Stupin notes it's "not so scary as it might sound" for auditing purposes.
  1. Test the Entire Ecosystem, Not Just GraphQL: Given that GraphQL often acts as an aggregation layer for underlying REST APIs, microservices, and databases, defensive strategies must extend beyond the GraphQL layer itself. Comprehensive security testing must include all integrated backend systems, as vulnerabilities in these components can still be exploited via the GraphQL interface.
  1. Prioritize Code Cleanliness and Consistency: Stupin implicitly links "clean code" with fewer vulnerabilities. Establishing clear coding standards and consistent access control patterns across the GraphQL API reduces complexity and the chance of developers introducing security flaws through oversight or inconsistent implementation.

By adopting these defensive measures, organizations can build secure GraphQL APIs that deliver on their promise of flexibility and efficiency without compromising data integrity or user privacy.

Key Takeaways

  • GraphQL is a powerful but often misconfigured API technology: Its rapid adoption by major companies underscores its benefits, but its novel architecture introduces new security challenges, especially around access control.
  • Access control is the primary security concern in GraphQL APIs: Unlike traditional REST APIs, GraphQL's flexibility in data fetching and modification often leads to overlooked authorization checks, making it the "most big problem."
  • "Broken edges" are a unique GraphQL vulnerability type: Developers frequently forget to implement access control on data associated with the connections (edges) between objects, leading to significant vulnerabilities and high bounties (e.g., $4,000 and $20,000).
  • GraphQL Voyager and GraphiQL are essential auditing tools: These tools facilitate understanding complex GraphQL schemas via introspection, transforming raw JSON into navigable graphs and providing an interactive environment for crafting queries.
  • Implement robust access control using resolvers or directives: Developers should choose between embedding checks directly in resolvers for simplicity or using GraphQL directives for more granular, declarative, and cleaner access control logic.
  • GraphQL's strong typing helps mitigate injection risks: The language's type validation significantly reduces the attack surface for vulnerabilities like SQL injection, but it doesn't eliminate the need for comprehensive security practices.

About the Speaker(s)

Nikita Stupin is a security researcher working for Mail.ru, a prominent Russian technology company known for its email services, cloud offerings, and gaming platforms. Based in Moscow, Nikita is actively involved in cutting-edge security research, with a particular focus on emerging technologies like GraphQL. He gained recognition for his work at conferences such as Insomni'Hack in Geneva, a partner conference of Swiss Cyber Storm. As an accomplished bug bounty hunter, Stupin has successfully identified and reported real-world vulnerabilities in production systems, earning significant bounties for his contributions to improving software security. His expertise lies in uncovering new attack vectors and proposing practical defense mechanisms for complex API architectures.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

Stupin's talk is a competent, entirely pragmatic bug hunter's view of GraphQL access control. He isn't dropping new exploit primitives, but rather pointing out a massive blind spot where developers consistently forget to write authorization checks.

Heather Calloway (CISO) — STRONG ACCEPT

If your engineering teams are adopting GraphQL for developer velocity, your AppSec program is probably flying blind. Stupin perfectly articulates how this architectural shift breaks traditional API security models, making it required viewing for any security team supporting modern frontend development.

→ Top-rated talks at Swiss Cyber Storm 2019

All talks from Swiss Cyber Storm 2019