OWASP Top 10 in GraphQL: An API Adventure

Danielle Rosenfeld-Lovell (Penetration Tester)

BSides Canberra VII (2024) · Day 2 · Bradman Theatrette

Overview

In this insightful talk from BSides Canberra, Danielle Rosenfeld-Lovell, an experienced penetration tester, takes attendees on an "API Adventure" through the landscape of GraphQL security. The presentation meticulously maps the OWASP API Security Top 10 risks to practical vulnerabilities within GraphQL implementations, highlighting how this increasingly popular API technology, despite its architectural advantages, remains susceptible to common security pitfalls. The talk is particularly aimed at those new to security and web technologies, providing a foundational understanding of API security in a GraphQL context.

Watch on YouTube

Visual summary for OWASP Top 10 in GraphQL: An API Adventure by Danielle Rosenfeld-Lovell
Visual summary for OWASP Top 10 in GraphQL: An API Adventure by Danielle Rosenfeld-Lovell

Key moments

  1. 0:40 Introduction to GraphQL and OWASP API Top 10
  2. 2:50 GraphQL: Single endpoint vs. RESTful API architecture
  3. 10:00 GraphQL introspection: Rapid API schema discovery
  4. 12:00 API1: Broken object level authorization (BOLA/IDOR) example
  5. 15:50 API4: Unrestricted resource consumption in GraphQL APIs
  6. 20:00 API7: Server-side request forgery (SSRF) in APIs
  7. 22:50 Conclusion: GraphQL testing takeaways and OWASP applicability

OWASP Top 10 in GraphQL: An API Adventure

Speakers: Danielle Rosenfeld-Lovell, Penetration Tester

Conference: BSides Canberra

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

Overview

In this insightful talk from BSides Canberra, Danielle Rosenfeld-Lovell, an experienced penetration tester, takes attendees on an "API Adventure" through the landscape of GraphQL security. The presentation meticulously maps the OWASP API Security Top 10 risks to practical vulnerabilities within GraphQL implementations, highlighting how this increasingly popular API technology, despite its architectural advantages, remains susceptible to common security pitfalls. The talk is particularly aimed at those new to security and web technologies, providing a foundational understanding of API security in a GraphQL context.

Rosenfeld-Lovell emphasizes the critical role of web applications and APIs in modern penetration testing, making a thorough understanding of their security risks indispensable. By focusing on GraphQL, a technology often perceived as relatively new but with roots dating back to 2012, she addresses a less commonly encountered but rapidly growing segment of the API ecosystem. The core message is that while GraphQL offers unique features like a single endpoint and powerful data fetching capabilities, these same characteristics introduce distinct ways in which established security risks manifest and can be exploited.

The presentation serves as a crucial guide for developers and security professionals alike, demonstrating that the principles of secure API design outlined in the OWASP API Security Top 10 remain highly relevant, even when applied to GraphQL's distinct architecture. Through practical examples from a deliberately vulnerable GraphQL application, Rosenfeld-Lovell illustrates how to identify and understand these vulnerabilities, providing actionable insights into securing GraphQL APIs against prevalent threats.

Background

▶ Watch: Introduction to GraphQL and OWASP API Top 10 (0:40)

The foundation of this talk rests on the OWASP API Security Top 10 for 2023, a critical update to the more general OWASP Top 10 for Web Applications (2021). While the web application list covers a broad spectrum of vulnerabilities, the API-specific list delves into risks pertinent to modern API-driven architectures. Rosenfeld-Lovell specifically chose the API Security Top 10 to provide a more targeted and current perspective on securing GraphQL.

GraphQL is introduced as an API implementation strategy designed to facilitate communication between a web front-end and a back-end server. Developed by Facebook (now Meta) in 2012, GraphQL offers a powerful and flexible alternative to traditional RESTful APIs. Its core appeal lies in its ability to allow clients to request precisely the data they need, thereby avoiding over-fetching or under-fetching of information. GraphQL is widely supported across various frameworks and programming languages, making it a ubiquitous choice for modern application development.

A key differentiator highlighted is GraphQL's single endpoint architecture, contrasting sharply with REST's resource-oriented approach, which typically involves numerous unique URIs for different resources. While the single endpoint can simplify inventory management to some extent, it shifts the security focus to the API's schema definition and authorization logic, as all interactions funnel through one access point.

To understand GraphQL's security implications, a grasp of its fundamental concepts is essential:

  • Schema Definition Language (SDL): This human-readable, JSON-like language is used to define the structure of the GraphQL API. It outlines objects, which are collections of data, and fields, which are the concrete data points within those objects. Fields can be scalars (basic types like String, Int, Boolean, Float) or other objects. Enums allow for self-defined lists of named values. SDL enables GraphQL to be implemented in a language-agnostic manner, allowing diverse clients and servers to communicate effectively.
  • CRUD Operations: GraphQL defines specific operation types for data manipulation:
  • query: Used for reading or fetching data (the "Read" part of CRUD).
  • mutation: Handles all data changes, including creating new objects, updating existing ones, and deleting data (the "Create," "Update," and "Delete" parts of CRUD).
  • subscription: Used for real-time updates and notifications, though less applicable to the specific vulnerabilities discussed in this talk.
  • Introspection: A powerful and often default-enabled feature in GraphQL. Introspection allows clients to directly query the API's schema to discover all available types, fields, queries, and mutations. This capability provides a comprehensive understanding of the API's functionality, which, while beneficial for developers, presents a significant information disclosure risk if exposed in production environments. In a RESTful context, achieving similar discovery could take days of content enumeration; with GraphQL introspection, it's often a single request away.

The talk uses a deliberately vulnerable GraphQL application, "Dem Vable Graph App," which is easily set up locally via Docker. This application simulates a public messaging forum where users can post comments, referred to as "pastes," providing a practical environment for demonstrating the OWASP API Top 10 risks.

Key Findings

▶ Watch: GraphQL introspection: Rapid API schema discovery (10:00)

The central finding of Danielle Rosenfeld-Lovell's talk is that the OWASP API Security Top 10 risks are fully applicable to GraphQL APIs, but their manifestation, exploitation vectors, and defensive strategies often differ significantly from traditional REST APIs. GraphQL's unique architectural characteristics, such as its single endpoint, schema-driven nature, and powerful introspection capabilities, fundamentally reshape how these vulnerabilities appear and are identified.

One of the most critical findings revolves around Introspection. While designed as a developer-friendly feature to understand an API's capabilities, its default enablement in many GraphQL implementations creates an immediate and substantial information disclosure risk. Attackers can leverage a single introspection query to map the entire API surface, including potentially sensitive administrative functions or undocumented data fields, which would otherwise require extensive reconnaissance in a REST environment.

Furthermore, GraphQL's flexibility, particularly concerning query batching and recursive queries, introduces specific and potent Denial of Service (DoS) vulnerabilities. Attackers can stack numerous queries into a single request, bypassing rate limits, or craft deeply nested queries that exhaust server resources, leading to service degradation or outages. This highlights that while GraphQL offers efficient data fetching, it also requires careful resource management and validation at the server level.

The talk also underscores that traditional authorization failures—Broken Object Level Authorization (BOLA/IDOR), Broken Object Property Level Authorization (BOPA), and Broken Function Level Authorization (BFLA)—remain prevalent. However, in GraphQL, these often manifest through the manipulation of object IDs within mutation operations, the exposure of sensitive fields during queries, or the unauthorized execution of powerful administrative mutations. The schema's explicit definition of types and fields means that authorization logic must be rigorously applied at these granular levels, rather than relying solely on endpoint protection.

In essence, the key findings confirm that GraphQL is not inherently more secure than other API architectures. Instead, its distinct design requires security professionals and developers to adapt their understanding of common API security risks, focusing on GraphQL-specific exploitation patterns and implementing tailored defensive controls.

Technical Deep Dive

▶ Watch: API1: Broken object level authorization (BOLA/IDOR) example (12:00)

Danielle Rosenfeld-Lovell systematically walks through each of the OWASP API Security Top 10 risks, illustrating their presence and exploitation within a GraphQL context using examples from the "Dem Vable Graph App."

API1: Broken Object Level Authorization (BOLA)

Also known as IDOR (Insecure Direct Object References), BOLA occurs when a user can access or modify objects they are not authorized for by manipulating object IDs. In the GraphQL example, a public paste by a user named "Khen" has an easily enumerable object ID. Without proper authorization checks, an attacker can craft a mutation operation to modify or "deface" this paste, or any other paste, across the entire system by simply changing the id parameter. This demonstrates a fundamental failure to link object access to the authenticated user's permissions.

API2: Broken Authentication

This category covers flaws in authentication mechanisms, allowing attackers to bypass login, assume other user identities, or gain excessive privileges. While the lab environment intentionally lacks complex authentication, Rosenfeld-Lovell demonstrates a simple bypass. A GraphQL development environment, typically part of the application, might have access controls enforced via a cookie. By identifying a cookie with a value like disable and changing it to enable, an attacker can bypass the control and gain unauthorized access to run queries and interact with the API, highlighting how weak session management or insecure cookie handling can lead to authentication bypasses.

API3: Broken Object Property Level Authorization (BOPA)

BOPA focuses on authorization failures at the field or property level within an object. It has two main subclasses:

  • Excessive Data Exposure: This occurs when an API exposes more data than necessary, often sensitive information. The example illustrates this by showing how a user can query for other users' public IP addresses, a piece of sensitive data that should not be broadly accessible. The GraphQL schema might define this field, but the authorization logic fails to restrict its visibility based on the requesting user's role or identity.
  • Mass Assignment: This vulnerability allows an attacker to manipulate hidden or unintended parameters/fields in an object, often to elevate privileges or alter data. For instance, an attacker might discover a role parameter that was not explicitly included in their request but can be injected with a value like admin, thereby gaining administrative privileges if the server-side validation is insufficient.

API4: Unrestricted Resource Consumption

This risk involves an API's susceptibility to resource exhaustion, leading to Denial of Service (DoS) or excessive operational costs. GraphQL presents two notable vulnerabilities here:

  • Query Batching: GraphQL allows clients to send multiple independent queries within a single request. If not properly rate-limited or monitored, an attacker can stack a large number of queries into one request. Since GraphQL servers often process these queries in parallel, this can bypass traditional request-based rate limiting and rapidly consume computational resources, leading to DoS.
  • Denial of Service by Recursion: Due to GraphQL's hierarchical, tree-like structure, it's possible to nest queries within queries. An attacker can craft a deeply recursive query (e.g., user { friends { friends { ... } } }) that repeatedly fetches related objects, leading to an extremely resource-intensive operation that can exhaust memory or CPU, causing a DoS.

Defensive measures for unrestricted resource consumption include:

  • Maximum Query Depth Limits: Restricting how many levels deep a query can nest.
  • Request Timeouts: Dropping queries that take longer than a predefined duration to process.
  • Cached Responses: Returning pre-computed results for popular or repetitive queries to reduce processing load.
  • Cost Analysis: Dynamically calculating the computational cost of a query before execution and rejecting overly expensive ones. (This can be computationally expensive itself, requiring careful implementation).

API5: Broken Function Level Authorization (BFLA)

BFLA occurs when a user can access or execute administrative or highly privileged functions they are not authorized for. Rosenfeld-Lovell provides a stark example: an administrative mutation operation like deleteAllPastes is left accessible to regular users. When a user invokes this mutation, expecting it to only delete their own content, it inadvertently deletes everyone's comments across the entire system. This highlights the danger of insufficient authorization checks on powerful, system-wide functions.

API6: Unrestricted Access to Sensitive Business Flows

This risk involves the ability to automate or trigger sensitive business functionality without proper controls, often leading to abuse. The "silly example" given is spamming the message board with 100 comments via an automated script. A more topical real-world example cited is the use of bots for concert ticket scalping, where automated API calls bypass human interaction limits. While making business processes multi-step can deter casual attackers, a determined attacker can still script multi-step API calls, emphasizing the need for more comprehensive solutions like behavioral analysis or CAPTCHAs.

API7: Server Side Request Forgery (SSRF)

SSRF is notable as the only specific vulnerability class explicitly mentioned in the OWASP API Top 10. It allows an attacker to compel the server-side application to make arbitrary requests to an attacker-controlled URL or internal network resources. The example uses a vulnerable file import functionality to access a web service running on the local device, demonstrating how an attacker can use the application as a proxy to interact with internal systems. Rosenfeld-Lovell notes that while direct SSRF is rare in real-world scenarios, inference-based SSRF, where the attacker deduces information from server responses, is more common and requires extensive investigation.

API8: Security Misconfiguration

This is a broad category encompassing various insecure configurations, including default settings, incomplete configurations, and exposed debug interfaces. A prime GraphQL-specific example is introspection being enabled by default in production environments. As previously discussed, this hands an attacker a complete map of the API, including potentially "very secret administrative functionality" that should never be publicly disclosed. Other examples include leaving open ports, debug features, or insecure error messages.

API9: Improper Inventory Management**

This risk highlights poor visibility and control over an organization's API landscape. It manifests in two subcategories:

  • Documentation Blind Spots: APIs that are either undocumented from the outset or whose documentation becomes outdated and unmaintained. This makes it difficult for both developers and security teams to understand an API's purpose, functionality, and security requirements.
  • Data Flow Blind Spots: A lack of oversight regarding data flows between an application and third-party services. Organizations may have poor understanding of what data is shared, how it's processed, and whether these external data flows are justified and secure from a business perspective.

API10: Unsafe Consumption of APIs**

This final category addresses the risks associated with an application excessively trusting or improperly consuming external APIs, particularly third-party services. While hard to demonstrate in a simple lab, common scenarios include:

  • Lack of Input Validation: Consuming data from a third-party API without adequate input validation, which can lead to injection vulnerabilities (e.g., SQL injection, XSS) within the consuming application.
  • Insufficient Security Checks: Sharing sensitive data with a third-party service without verifying that the third party applies the same rigorous confidentiality and protection standards to that information. This can lead to data breaches originating from trusted external partners.

Demo / Proof of Concept

▶ Watch: API7: Server-side request forgery (SSRF) in APIs (20:00)

Throughout her presentation, Danielle Rosenfeld-Lovell utilized a deliberately vulnerable GraphQL application named "Dem Vable Graph App" to illustrate each of the OWASP API Security Top 10 risks. This application, which is publicly available as a Docker instance, simulates a public messaging forum where users can create, read, update, and delete "pastes" (comments).

While no live coding or full-fledged interactive demo was performed, the core of the proof-of-concept demonstrations consisted of request and response pairs from this vulnerable application. For each API security risk, Rosenfeld-Lovell presented:

  • An example GraphQL query or mutation operation crafted to exploit a specific vulnerability.
  • The corresponding response from the "Dem Vable Graph App" showing the successful (and often "silly") outcome of the exploitation, such as defacing another user's paste (API1), bypassing authentication via a cookie manipulation (API2), or deleting all pastes on the system (API5).

This approach effectively served as a series of mini-demonstrations, visually articulating how GraphQL's unique features, such as its single endpoint, mutation operation types, and introspection capabilities, can be leveraged by an attacker when security controls are absent or misconfigured. The "Dem Vable Graph App" provided a concrete, local environment for understanding these theoretical concepts in a practical, albeit simplified, context.

Defensive Implications

▶ Watch: Conclusion: GraphQL testing takeaways and OWASP applicability (22:50)

Securing GraphQL APIs requires a proactive and comprehensive approach that acknowledges its unique architecture while adhering to general API security best practices. Defenders should consider the following implications:

  1. Manage Introspection Rigorously: Introspection is a powerful development tool but a severe information disclosure risk in production. It should be disabled in production environments or, at a minimum, restricted to authenticated and authorized users with specific roles (e.g., internal developers only). This prevents attackers from easily mapping the entire API surface.
  1. Implement Granular Authorization: Authorization must be enforced at multiple levels:
  • Object-Level (BOLA): Ensure that every query and mutation operation verifies the requesting user's permission to access or modify the specific object (e.g., a paste by its ID).
  • Property-Level (BOPA): Control access to individual fields within an object based on the user's role or context. Prevent excessive data exposure by default and implement strict validation against mass assignment attacks.
  • Function-Level (BFLA): Critical mutation operations (e.g., deleteAllPastes) must have robust authorization checks to ensure only highly privileged users can execute them.
  1. Strengthen Authentication and Session Management: Implement robust authentication mechanisms, including multi-factor authentication. Securely manage session tokens, ensuring they are short-lived, stored securely, and invalidated upon logout or suspicious activity. Avoid using simple cookie values as the sole authentication/authorization control.
  1. Mitigate Unrestricted Resource Consumption (DoS):
  • Query Depth Limiting: Implement server-side controls to limit the maximum nesting depth of GraphQL queries to prevent recursive DoS attacks.
  • Query Cost Analysis: Assign a computational cost to each field and reject queries that exceed a predefined total cost.
  • Rate Limiting: Implement intelligent rate limiting that considers the complexity of GraphQL queries, not just the number of requests.
  • Request Timeouts: Configure timeouts for GraphQL operations to prevent long-running, resource-intensive queries from monopolizing server resources.
  1. Secure Business Flows: Design sensitive business processes to be inherently resistant to automation. This may involve multi-step workflows, but crucially, also incorporate anti-bot mechanisms like CAPTCHAs, behavioral analytics, or device fingerprinting to detect and deter automated abuse.
  1. Comprehensive Security Configuration: Adhere to the principle of least privilege for all configurations. Disable unnecessary features, remove default credentials, ensure secure error handling that doesn't leak sensitive information, and apply security patches promptly. Regularly audit configurations for missteps.
  1. Robust Inventory and Asset Management: Maintain a complete and up-to-date inventory of all GraphQL APIs, including internal and third-party integrations. Ensure comprehensive documentation for each API, detailing its purpose, data flows, and security requirements. Regularly review data flows to third-party services for justification and security posture.
  1. Secure Consumption of Third-Party APIs: When integrating with external services, treat all incoming data as untrusted. Implement strict input validation, sanitization, and output encoding. Conduct thorough due diligence on third-party APIs, assessing their security controls and contractual obligations regarding data protection.
  1. Regular Security Testing: Conduct regular penetration testing and security audits specifically tailored to GraphQL APIs. Testers should be familiar with GraphQL-specific attack vectors, including introspection abuse, query batching, and recursive queries, to uncover vulnerabilities unique to this technology.

By focusing on these defensive strategies, organizations can significantly enhance the security posture of their GraphQL APIs, ensuring that the benefits of this flexible technology are realized without introducing undue risk.

Key Takeaways

  • GraphQL is a powerful and flexible API technology, widely supported and offering advantages like a single endpoint, but it introduces unique security considerations that differ from traditional REST APIs.
  • The OWASP API Security Top 10 risks are fully applicable to GraphQL, demonstrating that fundamental security principles remain constant, even if the exploitation vectors and defensive strategies adapt to GraphQL's architecture.
  • GraphQL Introspection is a critical information disclosure risk if enabled in production, allowing attackers to easily map the entire API schema, including potentially sensitive functionalities, with a single request.
  • GraphQL's query batching and recursive query capabilities introduce specific Denial of Service (DoS) vulnerabilities, necessitating robust controls like query depth limits, cost analysis, and intelligent rate limiting to prevent resource exhaustion.
  • Authorization failures (BOLA, BOPA, BFLA) are prevalent in GraphQL, requiring granular security checks at the object, property (field), and function (mutation) levels to prevent unauthorized data access, modification, or execution of privileged operations.
  • Comprehensive security practices, including secure configuration, proper inventory management, and careful consumption of third-party APIs, are essential for mitigating the broad spectrum of risks associated with GraphQL implementations.

About the Speaker(s)

Danielle Rosenfeld-Lovell is a dedicated penetration tester with a strong preference for working with web technologies. Her expertise extends to dabbling in cloud security and secure code review. Beyond her professional life, Danielle is a proud cat mom to two spoiled cats and enjoys prolific knitting in her spare time. She brings a practical, hands-on perspective to the field of cybersecurity, focusing on making complex topics accessible, especially for those new to security.

Reviews

→ Top-rated talks at BSides Canberra VII (2024)

All talks from BSides Canberra VII (2024)