OWASP Top 10 API Security Risks – 2023: API10:2023 – Unsafe Consumption of APIs
In 2023, the OWASP Top 10 API Security Risks continues to serve as a critical framework for organisations seeking to address security vulnerabilities in their Application Programming Interfaces (APIs). Among these risks, API10:2023 – Unsafe Consumption of APIs stands out as one of the most significant threats to the integrity and confidentiality of both corporate and third-party services.
For software developers and penetration testers, understanding and mitigating unsafe consumption risks is pivotal not only to secure APIs but also to protect the sensitive data of users and organisations alike. In this blog post, we will delve deeply into this vulnerability, unpacking its causes, implications, and providing a thorough guide to securing APIs against this risk.
What is “Unsafe Consumption of APIs”?
The term “unsafe consumption of APIs” refers to the practice where developers trust data received from third-party APIs more than they trust user input, leading to weaker security standards for the data coming from these integrated services. Typically, this occurs because third-party APIs are seen as more “trusted” than direct user input, so developers may not apply the same level of scrutiny or security measures when consuming data from these external sources.
The nature of this issue lies in how data is validated and processed. If an attacker can manipulate or compromise an integrated third-party service, they can exploit the weak consumption patterns, bypassing security controls and causing harm to the target API.
The Risk Landscape
APIs are a crucial element of modern applications. With businesses increasingly reliant on third-party services, the likelihood of interacting with untrusted or compromised APIs grows. Whether it is payment gateways, external data services, or even authentication providers, these third-party integrations are often seen as part of a trusted ecosystem.
However, APIs that rely too heavily on these integrations without proper validation or secure consumption practices can become prime targets for attackers. Since organisations typically focus their security efforts on safeguarding their own APIs, vulnerabilities in the consumption of third-party APIs are frequently overlooked, leaving them exposed to a range of malicious activities.
Real-World Example: A Case Study in API Vulnerabilities
A prime example of unsafe consumption can be seen in the infamous Equifax data breach of 2017, which was partly attributed to insecure API consumption practices. Equifax used third-party APIs to access critical data, but poor security controls allowed attackers to exploit weaknesses in those integrations. By targeting the APIs directly rather than Equifax’s internal systems, hackers gained access to personal information of over 147 million Americans. This breach serves as a stark reminder that the security of APIs — especially those involving third-party services — cannot be taken for granted.
Real-World Examples of Unsafe Consumption of APIs
The concept of unsafe consumption of APIs has led to several significant breaches and vulnerabilities in the past. Below, we explore some real-world examples where attackers have exploited the unsafe consumption of third-party APIs to compromise applications and organisations. These cases underscore the importance of rigorous security measures when integrating with third-party services.
1. Uber’s 2016 Data Breach
In 2016, Uber suffered a significant data breach due to the unsafe consumption of third-party APIs. Attackers gained access to sensitive information by exploiting weak API consumption practices in Uber’s infrastructure.
Uber used an external service for handling user authentication, which was vulnerable to API manipulation. The attackers discovered an insecure API endpoint and gained access to a private GitHub repository. This repository contained sensitive credentials, including AWS access keys, which allowed them to further penetrate Uber’s network.
The breach exposed the personal information of 57 million Uber customers and drivers, including names, email addresses, phone numbers, and even driving history. The breach could have been prevented if Uber had enforced stricter validation on the data received from third-party APIs and had better controls over how sensitive information, like API keys, was handled.
Key Lesson: This breach highlights the risks of blindly trusting third-party services and the importance of secure API consumption, especially when dealing with sensitive data such as authentication credentials and access tokens.
2. Facebook’s Vulnerability via Instagram’s API (2018)
In 2018, Facebook was affected by an issue with the Instagram API, which allowed attackers to manipulate API calls to take control of accounts and access sensitive user data. The vulnerability stemmed from improper data validation practices when integrating third-party services, allowing unauthorised API consumption.
Attackers could exploit the lack of validation by sending specific data manipulations through Instagram’s API. In this case, Instagram’s API allowed attackers to access private information by sending an improperly sanitised request. This could lead to account takeovers, or worse, the leakage of sensitive personal information stored on Instagram.
Though Facebook quickly patched the issue and responded to the vulnerability, the incident demonstrated the risk of third-party service misconfigurations when handling data from external sources.
Key Lesson: This incident showcases how improper validation of API responses can result in significant risks to user privacy, especially when dealing with services that hold large amounts of personal information. It also underscores the importance of regularly auditing APIs to catch potential vulnerabilities.
3. Capital One Data Breach (2019)
One of the most notable breaches caused by unsafe API consumption was the Capital One data breach in 2019. Attackers exploited a vulnerability in Capital One’s use of a third-party API provided by Amazon Web Services (AWS) to access sensitive data from over 100 million customers.
The vulnerability occurred because Capital One’s API was misconfigured, allowing an attacker to send malicious commands to the AWS server and extract sensitive data, including credit scores, personal information, and transaction data. The breach was made possible because Capital One’s API failed to properly validate data coming from the third-party AWS service, giving the attacker an opportunity to manipulate the API call and access private data.
The breach was traced back to a specific misconfiguration within Capital One’s API firewall, which was being bypassed by the attacker. This issue was compounded by a failure to properly secure the data being exchanged between APIs.
Key Lesson: This breach serves as a significant warning about the importance of securing API gateways, implementing robust data validation, and monitoring the consumption of third-party services. Misconfigurations and poor validation in third-party services can open the door to attackers exploiting weaknesses in the API consumption process.
4. Twitter API Vulnerability (2022)
In 2022, Twitter experienced a significant vulnerability through its API that allowed attackers to access private user data. The vulnerability stemmed from a failure to properly authenticate API requests made to certain endpoints, allowing an attacker to manipulate data exchanged between Twitter’s internal services and third-party integrations.
The attack involved exploiting API endpoints that failed to validate input data correctly, enabling the attacker to retrieve user account information, such as email addresses and phone numbers, from the platform. This breach affected over 5.4 million Twitter users and raised concerns about the security of user data accessed via third-party services.
As with the other examples, the root cause of the vulnerability was insufficient data validation from third-party APIs and improper handling of input data. If Twitter had followed best practices for securing external API calls, it could have prevented this breach and safeguarded user privacy.
Key Lesson: The Twitter API breach is a reminder of how APIs that interact with external services or handle external data must be properly secured to avoid exposing sensitive information. Tight authentication, data validation, and real-time monitoring are critical to mitigating such risks.
5. The Slack API Incident (2020)
Slack, a popular communication platform, faced a vulnerability in 2020 that exposed sensitive user data due to unsafe consumption of third-party APIs. In this case, attackers were able to exploit a flaw in the way Slack interacted with third-party service providers, particularly those used for authentication and user management.
The attackers used manipulated API calls to bypass authentication mechanisms in Slack’s API, which allowed them to gain unauthorised access to user conversations, private channels, and sensitive business data. This vulnerability stemmed from insufficient data validation and over-trusting of the third-party services involved in Slack’s authentication flows.
Slack’s response to the breach was to implement additional security measures and strengthen the validation process for third-party APIs. However, the incident underscored the importance of ensuring that external services, especially authentication providers, are not only trusted but also monitored and validated for security risks.
Key Lesson: This breach reinforces the importance of reviewing third-party authentication and service integration regularly, as relying on unverified data or services can lead to significant security lapses. Robust API security measures, especially around user data, are crucial to preventing such incidents.
The Dangers of Unsafe API Consumption
1. Third-Party Data Manipulation
When a developer trusts data from a third-party API without verification or appropriate validation, malicious actors can manipulate that data. For instance, attackers may inject harmful payloads into the data returned by the third-party service. If this data is consumed without scrutiny, it can result in the execution of malicious actions, data leakage, or even access control violations.
2. Exposing Sensitive Data
An unsafe consumption pattern may also lead to the exposure of sensitive information. For example, API calls that fail to validate third-party data could unknowingly expose private user details or confidential business data. This data can be intercepted by malicious entities, leading to data theft or loss.
3. Bypassing Security Controls
By exploiting weaknesses in how external data is consumed, attackers can bypass existing security mechanisms. These mechanisms might include validation rules, input sanitisation processes, and security headers. If an external service returns untrusted data that is blindly consumed, these security checks become useless.
4. Increased Attack Surface
Every third-party service integrated into an API increases its attack surface. Unsafe consumption of API responses from these services heightens the overall risk, as attackers could target the weakest link in the integration chain. This could allow attackers to launch denial-of-service (DoS) attacks, gain unauthorised access to systems, or escalate privileges within the organisation’s network.
How Attackers Exploit Unsafe Consumption
Attacks leveraging unsafe API consumption often follow a particular sequence, which penetration testers and developers should be aware of to better defend against them. The general attack flow looks like this:
- Identifying Targeted Third-Party APIs: The first step for attackers is to identify third-party APIs that the target organisation is consuming. This can often be done through public API documentation or by reverse engineering the application to discover the services it communicates with.
- Manipulating API Data: Once a vulnerable third-party API is identified, attackers can inject malicious data into API responses. This could involve crafting specially designed payloads, such as SQL injection attempts or cross-site scripting (XSS) vectors, that can manipulate the API’s logic or trigger a vulnerability.
- Exploiting Trust Issues: Since the organisation’s API is likely to trust the data coming from the third-party service, it may fail to properly validate or sanitise the manipulated data, allowing the attacker to bypass security measures and launch their attack.
- Compromising the Target API: The malicious data or code injected via the third-party API is then consumed by the vulnerable API, triggering security lapses such as privilege escalation, unauthorised access, or data breaches.
Addressing Unsafe Consumption: Best Practices
As a software developer or penetration tester, securing API consumption practices is crucial in preventing potential exploits. Here are several steps to mitigate the risk of unsafe API consumption:
1. Strict Input Validation
The first line of defence against unsafe API consumption is strict input validation. Just because data comes from a third-party API does not mean it should be trusted implicitly. Always validate, clean, and sanitise data before it is processed or passed to any other part of the application.
Example:
If an external API provides a JSON response containing user email addresses, ensure that these emails are properly validated and do not contain unexpected characters or formats that could lead to SQL injection or other attacks.
2. Use Strong Authentication for Third-Party Services
To reduce the likelihood of malicious data being injected into an API response, implement strong authentication mechanisms for all third-party services. This may include using OAuth, API keys, and certificates, ensuring that only authorised services can interact with your API.
3. Implement Proper Access Control
Ensure that your API applies proper access control mechanisms to data received from third-party services. This may involve role-based access control (RBAC) or attribute-based access control (ABAC) to restrict who can access certain data and prevent unauthorised users from consuming sensitive third-party data.
4. Use Secure Transmission Protocols
Data exchanged between your API and third-party services should always be transmitted over secure protocols, such as HTTPS. This ensures that any data flowing through the network is encrypted and protected from interception by attackers.
5. Apply Rate Limiting and Logging
Implement rate limiting and comprehensive logging to monitor the interactions between your API and third-party services. By tracking and analysing traffic, you can identify unusual patterns that may suggest an attack or data manipulation attempt, allowing you to respond more quickly.
6. Regular Security Audits
Conduct regular security audits of both your internal APIs and the third-party services you rely on. These audits should include a review of how external data is being consumed, ensuring that proper security controls are in place.
7. Use API Gateways with Filtering Capabilities
An API gateway can act as a protective barrier between your services and external APIs. With built-in filtering and validation capabilities, an API gateway can ensure that only trusted data is consumed, mitigating the risk of unsafe data consumption.
8. Educate and Train Developers
Finally, it is essential to educate and train developers about the risks of unsafe API consumption and the importance of secure coding practices. Developers should be aware of the security implications of consuming third-party APIs and follow best practices to mitigate risks.
Final Thoughts: Strengthening the API Ecosystem
The rise of APIs as the backbone of modern digital ecosystems means that securing them has become more critical than ever. While third-party integrations offer valuable functionality and scalability, they also introduce significant security risks if not handled properly. By recognising and addressing the threat of unsafe consumption of APIs, organisations can prevent attackers from exploiting these integrations, safeguarding their users and sensitive data.
For software developers and penetration testers, ensuring the secure consumption of third-party APIs requires a deep understanding of the potential risks and proactive implementation of best practices. Through strict validation, robust authentication, and continuous security assessments, businesses can significantly reduce their exposure to these vulnerabilities and build more resilient API architectures.
In an era where security is paramount, mitigating the risks associated with unsafe API consumption is not just a technical concern but a strategic business imperative.
The Broader Impact of Unsafe API Consumption
These real-world examples demonstrate the risks associated with unsafe consumption of third-party APIs and the potentially devastating consequences for businesses and consumers alike. Whether through misconfiguration, lack of proper validation, or trusting external data without scrutiny, these vulnerabilities expose the fragility of modern digital ecosystems, where APIs serve as a backbone for functionality.
Organisations must recognise that while APIs provide great flexibility and integration opportunities, they also introduce security risks that need to be carefully managed. By adopting best practices for secure API consumption, such as input validation, strong authentication, and thorough security audits, organisations can significantly reduce their vulnerability to exploits that target third-party services.

For software developers and penetration testers, staying ahead of these risks requires ongoing education, vigilant security monitoring, and proactive implementation of security measures to ensure that APIs remain secure in a rapidly evolving technological landscape.