StackHawk
Hamburger Icon

Applying the OWASP
API Security Top 10
to GraphQL APIs

Nicole Jones

Nicole Jones|February 1, 2024

Learn how the OWASP API Security Top 10 vulnerabilities apply uniquely to GraphQL, with insights, examples, and practical tips. Plus, discover how tools like StackHawk automate security testing for proactive GraphQL protection.

As developers, we are well aware that APIs have become an essential part of modern web and mobile applications. Without them, many applications would be unable to facilitate the driving the seamless connectivity between different software components and services that users have come to expect. As APIs continue to grow in both importance and complexity, securing them against potential threats has become a critical challenge for developers and security professionals alike. When it comes to resources for establishing what vulnerabilities to focus on, The Open Web Application Security Project (OWASP) API Security Top 10 list is a vital source of information that highlights the most pressing security risks facing APIs today.

Among the various API technologies that developers currently use, GraphQL has emerged as a game changer, redefining how developers query and manipulate data. Developed by Facebook and released to the public in 2015, GraphQL offers a more efficient, powerful, and flexible alternative to the traditional REST API. From small startups to tech giants, many have embraced GraphQL for its dynamic approach to data retrieval and manipulation. With this growth in adoption and usage, understanding the security implications of GraphQL APIs is more crucial than ever.

In this blog, we will bridge the gap between the general security principles outlined in the OWASP API Security Top 10 and the specific needs of GraphQL APIs. We’ll explore each of the vulnerabilities in the top ten, unraveling how they apply to GraphQL. For each risk, we will do a quick analysis, including real-world scenarios, practical examples, and how to mitigate such vulnerabilities. By the end of this blog, you’ll have a comprehensive understanding of not only what makes GraphQL unique but also how to approach the security challenges that GraphQL adoption brings. First stop, let’s take a look at the OWASP API Security Top Ten in more detail before going into how they apply to GraphQL APIs.

What is the OWASP API Security Top Ten?

The Open Web Application Security Project (OWASP) is an international non-profit organization dedicated to improving the security of software. Within its many projects, the OWASP API Security Top Ten is the leading resource API developers can use to understand and mitigate the most significant security threats facing web APIs, including GraphQL. Released for the first time in 2019, this list is derived from industry survey data, expert opinions, and reported incidents. The goal of OWASP is to update it periodically to reflect the evolving landscape of API security. The latest update was in 2023.

The OWASP API Security Top 10 list categorizes and prioritizes the top security risks based on their prevalence, potential impact, and exploitability. The 2023 edition includes the following vulnerabilities:

1. Broken Object Level Authorization (BOLA)

2. Broken Authentication

3. Excessive Data Exposure

4. Lack of Resources & Rate Limiting

5. Broken Function Level Authorization

6. Mass Assignment

7. Security Misconfiguration

8. Injection

9. Improper Assets Management

10. Insufficient Logging & Monitoring

Each item on the list encapsulates a broad category of vulnerabilities, offering insights into their causes, manifestations, and potential impacts. This framework guides developers, security analysts, and IT professionals in creating, deploying, and maintaining secure APIs. To view the entire resource, you can check out the OWASP site.

Are the OWASP API Security Top Ten Applicable to GraphQL Endpoints?

At its core, the OWASP API Security Top 10 addresses concerns that are universally applicable to all types of APIs, including REST and GraphQL. These risks encompass broad security areas like authentication, authorization, data exposure, etc. However, because of how GraphQL APIs work, using GraphQL introduces unique challenges and subtleties in applying these security principles compared to RESTful APIs.

REST vs. GraphQL

When it comes to the debate of what technology to use, most will find that their organization will use a mix of both technologies. The idea of RESTful APIs being entirely deprecated as a technology is a bit of a stretch. REST (Representational State Transfer) APIs have been the standard for web services for many years, characterized by their stateless nature and standard HTTP methods (GET, POST, PUT, DELETE). They are so extensively used that the majority of APIs being used are RESTful. In contrast, GraphQL, seen as a query language for APIs, offers a more dynamic and flexible approach to the function of an API. GraphQL, unlike REST APIs, allows clients to request exactly the data they need in a single query. 

There are a few areas of consideration when comparing the two technologies. Here are a few areas where the two technologies differ:

  • Authorization: In REST, authorization checks are often tied to specific URL endpoints. GraphQL, however, handles a wide range of data through a single endpoint, necessitating more granular, field-level authorization checks.

  • Data Exposure: REST APIs may expose different endpoints for different data needs, while GraphQL’s single endpoint approach can lead to excessive data exposure if not carefully managed.

  • Rate Limiting: REST APIs typically rate limit based on the number of requests, but for GraphQL, the complexity of queries also needs to be considered, as a single query can be resource-intensive.

With these points in mind, developers should be able to tell that applying the OWASP Top 10 to GraphQL requires a deeper understanding of the nuances of GraphQL. For example, below are a few points within the OWASP API Top Ten and how the nuances of GraphQL apply to them.

BOLA & Function Level Authorization: 

GraphQL’s flexible querying can inadvertently bypass traditional object and function-level authorization controls. This means that GraphQL APIs must have robust and context-aware security implementations.

Authentication & Data Exposure: 

GraphQL’s use of a single endpoint for data retrieval can complicate authentication schemes and increase the risk of data exposure. GraphQL schemas handling sensitive data require comprehensive and adaptive security measures.

Complexity & Rate Limiting: 

The ability of GraphQL to handle complex queries in a single request means that traditional rate limiting based on request count is insufficient. Instead, more sophisticated approaches like analyzing query complexity and query depth limiting are required.

Injection & Misconfiguration: 

While GraphQL is less prone to traditional injection attacks, its resolvers can still be vulnerable. Similarly, misconfigurations in a GraphQL context can have far-reaching implications due to its singular endpoint and complex schema.

In conclusion, while the OWASP API Security Top 10 is universally applicable to all APIs, including GraphQL, the application of these principles requires a tailored approach. This tailored approach should account for GraphQL’s unique capabilities and challenges. Ensuring robust and adequate security in the face of evolving cyber threats is extremely important for all APIs, underscoring the importance of the Top Ten list.

Applying the OWASP API Security Top Ten to GraphQL

Now that we’ve looked at what the OWASP API Security Top Ten is, in this section, we’ll explore each vulnerability, discuss its relevance to GraphQL, and provide examples and prevention strategies. The breakdown below is based on the list published in 2023.

1. Broken Object Level Authorization (BOLA)

This risk involves unauthorized access to objects due to flaws in authorization mechanisms. Due to GraphQL’s single query structure, queries can expose sensitive data if proper authorization is not implemented. An example of this would be if a GraphQL query retrieves user profiles, including those of administrators, without adequate access checks. This would allow authorized and unauthorized users to access sensitive fields. To prevent this vulnerability, developers should implement robust authorization checks for each object, ensuring data access is adequately restricted.

2. Broken Authentication

This occurs when authentication mechanisms are implemented incorrectly, allowing attackers to compromise authentication tokens or exploit implementation flaws. With GraphQL APIs, this is particularly true given their single endpoint structure. For example, an attacker could exploit a weakly protected API key to access sensitive data via GraphQL queries. To prevent this from happening, developers should use robust and reliable authentication methods like OAuth 2.0 and regularly rotate API keys and tokens.

3. Broken Object Property Level Authorization

Combining Excessive Data Exposure and Mass Assignment from the 2019 list, this risk focuses on improper authorization at the object property level. In GraphQL, this might involve exposing or allowing modification of properties like user roles or personal data without proper checks. Prevent this by implementing strict authorization at the property level and validating inputs in queries and mutations.

4. Unrestricted Resource Consumption

APIs not protected with rate limiting or other resource-restricting measures can be vulnerable to DoS (Denial of Service) attacks and unlimited resource consumption. Complex GraphQL queries can consume excessive server resources, heightening this risk and leading to potential organization and financial repercussions. For example, an attacker could send a complex, nested query to overload the server. Depending on the complexity, this could overload the server and cause a server failure, resulting in a denial of service. On the other hand, if the server is set up to auto-scale to keep up with the demand, this could lead to a massive infrastructure bill. To prevent this, developers should implement rate limiting, query complexity analysis, and query-depth limiting. Many API gateway platforms can supply this functionality for GraphQL queries.

5. Broken Function Level Authorization

This risk involves users accessing functions beyond their permissions due to misconfigured authorization. In GraphQL, the issue can arise if function-level authorizations are not correctly managed. A great example of this would be if a regular/unauthorized user accesses a mutation that should be restricted to admins. Thus allowing the unauthorized user to access a function and potentially make changes they shouldn’t be able to. To prevent this, developers should rigorously define and enforce function-level permissions within GraphQL resolvers. Doing this will ensure that unauthorized function-level access is not possible, malicious or not.

6. Unrestricted Access to Sensitive Business Flows

This risk pertains to exposing business flows to excessive or automated use. In GraphQL, this could involve the API, including the resolvers that power it, allowing unchecked repetitive actions. An example of this type of exploit may be as simple as allowing a user to execute a mutation multiple times, resulting in mass account creation. To prevent this type of exploit, developers, at a minimum, should implement throttling and logic checks to control flow execution.

7. Server Side Request Forgery (SSRF)

SSRF flaws occur when an API fetches a remote resource without validating the user-supplied URI, making it susceptible to manipulation. For instance, in a GraphQL context, if an API blindly trusts a URL input for fetching data, an attacker could manipulate this input to make the server send a request to an internal or malicious destination. To prevent SSRF, validation mechanisms must be robust, ensuring all external URLs are verified before use. It’s crucial to implement checks that confirm URLs are safe and intended for the API’s usage and to restrict the API from accessing internal resources that could be targeted in an attack.

8. Security Misconfiguration

Inadequate configurations and security settings in APIs and their infrastructure can lead to various vulnerabilities. Default or poor configurations in GraphQL, especially in error messaging, can create security loopholes and lead to breaches. For example, as with RESTful APIs, GraphQL APIs that return verbose error messages can reveal sensitive API configuration details. To prevent these security concerns, ensure secure configurations for GraphQL APIs, minimize error details returned to users, and use the appropriate security headers.

9. Improper Inventory Management

This risk involves failing to track correctly and document APIs, which is particularly relevant for GraphQL with its multiple endpoints and versions. For example, a GraphQL service might have deprecated or development-only endpoints inadvertently exposed in production. Preventing this issue requires maintaining an up-to-date inventory of all deployed API versions and actively managing them. This includes routine audits to identify and decommission outdated or unused endpoints, ensuring only current and secure versions are available.

10. Unsafe Consumption of APIs

This risk addresses the weaker security often applied to data received from third-party APIs compared to user input. In a GraphQL API, integrating a third-party service without adequate security scrutiny can introduce vulnerabilities. For instance, if a GraphQL resolver integrates data from an external API with lax security, it could lead to data breaches or other security issues. To mitigate this, treat all data from external APIs with the same rigorous security standards as user input, including thorough validation and sanitization.

In this section, we’ve done a deep dive into the OWASP Top 10 vulnerabilities in the context of GraphQL APIs. By understanding these vulnerabilities, including their OWASP definitions, specific relevance to GraphQL, examples, and prevention strategies, developers and security professionals can better secure their GraphQL endpoints.

How StackHawk Can Help!

In the landscape of API security, tools like StackHawk have become indispensable for developers, especially when securing GraphQL APIs. StackHawk is a dynamic application security testing (DAST) tool designed to identify and rectify security issues in APIs. While it supports various types of APIs, it’s particularly adept at handling the unique challenges GraphQL poses.

One of StackHawk’s key strengths is its ability to automate security testing. This automation streamlines finding vulnerabilities in GraphQL APIs, seamlessly integrating security into the regular development workflow. Tailored to the distinct nature of GraphQL, StackHawk offers specialized testing capabilities that work with GraphQL schemas, enabling it to test the API intelligently. These tests help to uncover issues that might be overlooked by tools designed for more traditional REST APIs.

When it comes to addressing the OWASP Top 10 vulnerabilities, StackHawk offers broad coverage. Its testing capabilities can detect various security vulnerabilities, including many from the OWASP list. Once the platform detects an issue, StackHawk provides in-depth insights and actionable recommendations for each vulnerability. This level of detail is crucial for developers to not only understand the vulnerabilities but also to fix them in their code effectively.

StackHawk’s developer-centric approach means it easily integrates into CI/CD pipelines, allowing for regular and automated scanning of GraphQL APIs. This integration ensures a continuous security assessment of your APIS, helping teams to identify and address vulnerabilities early in the development cycle. StackHawk’s user-friendly interface and reports help make security accessible for developers with varying security expertise.

Conclusion

As we wrap up our exploration of applying the OWASP API Security Top 10 to GraphQL, it’s clear that understanding and mitigating these vulnerabilities is vital for anyone implementing GraphQL APIs. This blog has highlighted that while GraphQL brings unique advantages in API design, it also requires specialized attention to security, particularly in areas outlined by the OWASP Top 10.

Throughout this blog, we have underscored the importance of proactive measures and modern security tools like StackHawk. With its automated, GraphQL-focused capabilities, StackHawk equips developers to integrate security testing into their workflow seamlessly. Using StackHawk ensures that GraphQL APIs are robust and secure against the most pressing cyber threats.

In conclusion, embracing tools like StackHawk and staying informed about security best practices are key steps towards securing GraphQL APIs. By diligently applying the insights from the OWASP API Security Top 10, developers and security professionals can ensure their APIs are protected against vulnerabilities, paving the way for safer and more resilient API portfolio that includes GraphQL.


Nicole Jones  |  February 1, 2024

Read More

Understanding The 2023 OWASP Top 10 API Security Risks

Understanding The 2023 OWASP Top 10 APISecurity Risks

GraphQL API Security Best Practices

GraphQL APISecurity Best Practices

Long Live DAST! Evolution of Dynamic API Security Testing

Legacy DAST is DeadLong Live Modern DAST!