Hacking And Defending APIs: Red And Blue Make Purple

Matt Tesauro (AppSec Engineer)

Swiss Cyber Storm 2024 · Day 1 · Scenario

Overview

In his Swiss Cyber Storm talk, "Hacking And Defending APIs: Red And Blue Make Purple," Matt Tesauro, a seasoned AppSec Engineer and OWASP veteran, delivered a high-velocity, comprehensive exploration of API security. Tesauro's presentation served as a critical guide for both offensive (red team) and defensive (blue team) security practitioners, emphasizing the collaborative "purple team" approach necessary to secure the ubiquitous API landscape. The talk highlighted the inherent complexities of API ecosystems, contrasting them with traditional web applications and underscoring why APIs are rapidly becoming the primary target for attackers.

Watch on YouTube · Slides

Visual summary for Hacking And Defending APIs: Red And Blue Make Purple by Matt Tesauro
Visual summary for Hacking And Defending APIs: Red And Blue Make Purple by Matt Tesauro

Key moments

  1. 2:00 Why APIs are unique and challenging targets
  2. 6:10 API Security Posture, Runtime, Testing classifications
  3. 14:00 Deep dive: Broken Object Level Authorization (BOLA)
  4. 18:00 Broken User Authentication and JWT security
  5. 20:00 Excessive Data Exposure: a common developer mistake
  6. 25:30 Comprehensive list of API security tools
  7. 26:50 Greatest 'oops' moment during an API pen test

Hacking And Defending APIs: Red And Blue Make Purple

Speakers: Matt Tesauro, AppSec Engineer

Conference: Swiss Cyber Storm

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

Overview

In his Swiss Cyber Storm talk, "Hacking And Defending APIs: Red And Blue Make Purple," Matt Tesauro, a seasoned AppSec Engineer and OWASP veteran, delivered a high-velocity, comprehensive exploration of API security. Tesauro's presentation served as a critical guide for both offensive (red team) and defensive (blue team) security practitioners, emphasizing the collaborative "purple team" approach necessary to secure the ubiquitous API landscape. The talk highlighted the inherent complexities of API ecosystems, contrasting them with traditional web applications and underscoring why APIs are rapidly becoming the primary target for attackers.

Tesauro, drawing on his extensive experience as a "reformed programmer" turned application security expert, argued that APIs are the "data pipelines" of the modern era, akin to the "new oil." He meticulously detailed the unique attack surfaces presented by APIs, which often lack the browser-based security controls and human interaction elements that deter automated attacks on traditional web interfaces. The core of his presentation revolved around demystifying API vulnerabilities, particularly those outlined in the OWASP API Security Top 10, and providing actionable insights for both identifying and mitigating these risks.

This article delves into Tesauro's insights, providing a structured breakdown of the critical concepts, technical deep dives into common API attack vectors, and practical defensive strategies. It aims to distill the wealth of information shared, offering a robust understanding of why API security is paramount and how organizations can build more resilient API defenses by understanding both the attacker's mindset and the defender's toolkit.

Background

▶ Watch: Why APIs are unique and challenging targets (2:00)

The pervasive nature of Application Programming Interfaces (APIs) in modern software architectures is undeniable. From mobile applications and single-page web applications (SPAs) to microservices and Artificial Intelligence (AI) data ingestion, APIs are the connective tissue that enables data exchange and functionality across disparate systems. Matt Tesauro aptly describes APIs as "data pipelines," emphasizing their critical role in transporting the "new oil"—data—across the digital landscape. This fundamental shift towards API-driven development, while offering immense agility and scalability, simultaneously introduces a complex and often misunderstood security challenge.

Tesauro points out that while APIs conceptually seem simple—a program requesting data from another program over a network—their real-world implementations are anything but. Enterprise environments often feature intricate webs of APIs calling other APIs, traversing API Gateways, Web Application Firewalls (WAFs), and supporting various client types (mobile, SPA). This complexity creates a rich attack surface that traditional application security (AppSec) programs, primarily focused on browser-based web applications, may not adequately address. Tesauro highlights specific gaps in traditional AppSec tooling and controls, noting that elements like JSON Web Tokens (JWTs), OpenID Connect, OpenAPI/Swagger specifications, and API inventories are API-specific concerns often missing from established AppSec frameworks. While tools like SAST (Static Application Security Testing) and SCA (Software Composition Analysis) can analyze source code regardless of its API context, DAST (Dynamic Application Security Testing) tools have historically struggled with API-specific nuances, though they are improving.

A crucial distinction Tesauro makes is the stark difference in security controls between browsers and APIs. Browsers have evolved with robust security features like Multi-Factor Authentication (MFA), CAPTCHAs, and geolocation-based anomaly detection. These controls introduce friction for automated attacks. APIs, by design, are built for rapid, programmatic interaction and lack these human-centric security layers. Tesauro cites GitHub's experience, where increasing login page security directly correlated with a spike in API attacks, ultimately leading GitHub to remove direct username/password login from their API. This illustrates that APIs are inherently more attractive targets for attackers seeking automation, as they are "made to respond quickly," simplifying the attacker's life. This foundational difference necessitates a tailored approach to API security, moving beyond traditional AppSec paradigms to address the unique challenges of programmatic interfaces.

Key Findings

▶ Watch: Deep dive: Broken Object Level Authorization (BOLA) (14:00)

Tesauro structures API security into three major classifications and emphasizes a fundamental understanding of API definition. He asserts that comprehensive API security requires a holistic view, moving beyond isolated testing to embrace a continuous security lifecycle.

Firstly, API security can be broadly categorized into:

  1. API Security Posture: This involves understanding the complete inventory of APIs within an organization. It includes identifying which APIs exist, who should be calling them, the sensitivity of the data they handle, and their exposure level (internal, external, public-facing). A robust posture provides the foundational knowledge necessary to prioritize defensive efforts.
  2. Runtime API Security: This focuses on real-time monitoring of network traffic to and from APIs. The goal is to detect anomalies, suspicious patterns, and active attacks as they occur. This often involves deep packet inspection and behavioral analysis to identify deviations from normal API usage.
  3. API Security Testing: This is the proactive assessment of API vulnerabilities, ideally performed by well-trained individuals or specialized tools. Tesauro specifically highlights DAST (Dynamic Application Security Testing) as the most relevant testing methodology for APIs, as it interacts with the live API endpoint, unlike SAST or SCA which focus on source code.

Secondly, Tesauro underscores the critical importance of three fundamental components when defining and securing any API endpoint: the hostname, the path, and the HTTP method. He stresses that a change in even one of these factors can radically alter the security context and implications. For example, a GET /api/v1/users might be innocuous, but a DELETE /api/v1/users changes the security context entirely, demanding different authorization and access controls. Similarly, a POST /uat/admin/users might be acceptable in a User Acceptance Testing environment, but the same POST /production/admin/users is a critical security event. Ignoring these distinctions can lead to significant security oversights.

Finally, Tesauro leverages the OWASP API Security Top 10 as a practical framework for understanding and classifying the most common and critical API vulnerabilities. He walks through each category, dissecting them from both an attacker's perspective (how to exploit) and a defender's perspective (how to detect and prevent). This dual perspective forms the core of the "red and blue make purple" philosophy, encouraging a comprehensive approach to API defense.

Technical Deep Dive

▶ Watch: Broken User Authentication and JWT security (18:00)

Tesauro's technical deep dive primarily focuses on the OWASP API Security Top 10, illustrating each vulnerability with practical attacker methods and corresponding defensive challenges.

1. Broken Object Level Authorization (BOLA) / API1:2023 - Broken Function Level Authorization

Tesauro highlights BOLA as "super common" and a critical vulnerability. It occurs when an API validates a user's token but fails to verify if the user is authorized to access the specific resource requested.

  • Attacker Perspective: Look for IDs (numeric, UUIDs, string-based) in API requests. Manipulate these IDs to request data belonging to other users. If two users are available for testing, create a resource as user A, then attempt to access it as user B. Observe response codes and timings for clues.
  • Defender Perspective: This requires super deep inspection of API requests, as the traffic often appears legitimate. Traditional WAFs struggle because the JSON structure is correct; only the ID within the payload is unauthorized. Detection often relies on runtime analysis to identify patterns like a valid token requesting data for a different user. Proactive testing with known IDs for different users is crucial.

2. Broken User Authentication / API2:2023 - Broken Authentication

This category covers flaws in authentication mechanisms, allowing attackers to compromise accounts.

  • Attacker Perspective: APIs are ideal for brute-forcing credentials and password spraying due to their fast response times and lack of browser-based defenses (MFA, CAPTCHA). Misconfigurations in JWT (JSON Web Token) implementation (e.g., weak signing algorithms, improper validation) are common attack vectors. Tesauro recommends the "JWT best practices" guide as a vital resource.
  • Defender Perspective: Brute-force and password spraying attacks are often noisy and detectable through runtime monitoring. Code analysis of JWT generation and validation logic is essential. Tesauro strongly advises against implementing direct user login through APIs, suggesting human-driven web page logins to obtain tokens for API use.

3. Excessive Data Exposure / API3:2023 - Excessive Data Exposure

Developers often expose more data than necessary, leading to sensitive information leakage.

  • Attacker Perspective: Many frameworks simplify data serialization (e.g., to_json methods on ORM objects). Attackers, using a proxy, can observe the full JSON response, revealing fields that are not displayed in the UI but are present in the underlying data model.
  • Defender Perspective: This looks like legitimate traffic because it is legitimate from the API's perspective. Prevention is best achieved through SAST to identify overly broad database queries or to_json calls that serialize entire objects. Manual code review is also crucial to ensure only necessary data is exposed.

4. Lack of Resource & Rate Limiting / API4:2023 - Unrestricted Resource Consumption

APIs without proper rate limiting are vulnerable to abuse, denial-of-service, and brute-force attacks.

  • Attacker Perspective: Send a high volume of requests to discover vulnerabilities, brute-force credentials, or simply exhaust resources. Manipulating headers (e.g., X-Forwarded-For) might bypass basic rate limiting.
  • Defender Perspective: This is a noisy attack easily detectable by runtime monitoring. Proactive testing (fuzzing, load testing) should verify that rate limits are effective and not set so high that the API collapses before the limit is hit.

5. Broken Function Level Authorization / API5:2023 - Broken Function Level Authorization (formerly API4:2019)

Similar to BOLA but at the function level, allowing users to access administrative or privileged functions.

  • Attacker Perspective: Look for undocumented endpoints or HTTP methods. For example, a normal user might discover they can send a DELETE request to a resource that only administrators should manage, succeeding because the framework automatically exposed the method.
  • Defender Perspective: Watch out for APIs with two or more roles. This requires extensive testing, ideally with different user roles, to ensure that only authorized users can access specific functions. Frameworks that auto-generate API methods require careful auditing.

6. Mass Assignment / API6:2023 - Unrestricted Access to Sensitive Business Flows (formerly API6:2019)

The inverse of excessive data exposure, where attackers can send arbitrary values in requests that the API then uses to update database records, even if those fields were not intended to be user-modifiable.

  • Attacker Perspective: Send requests with additional fields in the JSON payload (e.g., isAdmin: true). If the API framework automatically maps these to database objects, the attacker can silently elevate privileges or alter data. These attacks often "silently fail unless they work," making them hard to detect without specific monitoring.
  • Defender Perspective: Requests in mass assignment attacks are often larger than normal. Decent runtime inspection should flag these. Server-side validation must explicitly whitelist allowed fields for updates, rather than blindly mapping all incoming JSON.

7. Security Misconfiguration / API7:2023 - Security Misconfiguration

This covers common security hygiene issues, such as default credentials, unpatched systems, exposed development interfaces, and misconfigured CORS policies.

  • Attacker Perspective: Standard vulnerability scanning tools (e.g., Nessus) can identify many of these issues. Look for common misconfigurations in HTTP headers, server configurations, and exposed debug endpoints.
  • Defender Perspective: Regular vulnerability scanning, hardening guides, and secure configuration baselines are essential. This is about foundational security practices.

8. Injection / API8:2023 - Injection

Just like traditional web applications, APIs are vulnerable to injection attacks (SQL, NoSQL, Command Injection, etc.) if they treat user-supplied data as executable code or commands.

  • Attacker Perspective: Identify any input field where data is accepted. Experiment with injection payloads based on the backend technology (e.g., ' OR 1=1-- for SQL). Good reconnaissance can reveal the underlying database or server type, informing payload choices.
  • Defender Perspective: Parameterized queries, input validation, and output encoding are the primary defenses. SAST tools can help identify potential injection points in code.

9. Improper Asset Management / API9:2023 - Improper Inventory Management (formerly API9:2019)

Lack of a clear inventory of all APIs, including deprecated versions and shadow APIs, leads to unmonitored and unsecured endpoints.

  • Attacker Perspective: It's hard for an attacker to know what the target doesn't know it has. However, discovery of forgotten or deprecated APIs can lead to easy wins because they are often unpatched and unmonitored.
  • Defender Perspective: Maintain a comprehensive, up-to-date API inventory. This includes documenting all versions, their purpose, and their lifecycle status. Without this, organizations cannot effectively monitor or secure their entire API surface.

10. Insufficient Logging & Monitoring / API10:2023 - Insufficient Logging and Monitoring

Lack of adequate logging and monitoring prevents timely detection and response to attacks.

  • Attacker Perspective: Attackers prefer environments with poor logging. They can perform suspicious actions (e.g., script tag in a phone number field resulting in a 200 OK) without generating alerts.
  • Defender Perspective: Implement robust logging for all API interactions, including successful and failed requests, authentication attempts, and authorization failures. Integrate logs with security information and event management (SIEM) systems for proactive monitoring and alerting. Without proper logging, debugging issues and detecting breaches become incredibly difficult.

Bonus: Fuzzing and Structural Attacks

Tesauro also briefly touches on advanced attack techniques:

  • Fuzzing: Randomly manipulating API input (parameters, headers, body) to discover crashes or unexpected behavior. This is highly effective for attackers and very noisy for defenders.
  • Structural Attacks: Beyond just fuzzing data, this involves manipulating the structure of the request itself. Tesauro recounts an anecdote of taking down a service by injecting "32 MB of space between two XML elements" in a single request, highlighting how unexpected structural inputs can lead to Denial of Service (DoS).
  • GraphQL: Tesauro mentions GraphQL as a complex API type that allows clients to query exactly what they need but can also expose the entire schema and lead to performance issues if not secured properly.

Demo / Proof of Concept

▶ Watch: Comprehensive list of API security tools (25:30)

While Matt Tesauro did not conduct a live, step-by-step demonstration during his accelerated talk, he provided a compelling real-world "war story" that vividly illustrates the impact of API vulnerabilities, specifically relating to Broken Object Level Authorization (BOLA) and Excessive Data Exposure.

Tesauro recounted an incident during an API penetration test at an insurance agency in the U.S. He discovered that the API allowed direct manipulation of the pagination number. Instead of requesting a limited number of records per page, he set the pagination number to "6,000 some odd," intending to retrieve all records at once. This action, an attempt to bypass intended resource limits and access an excessive amount of data, led to an 11-minute "sweaty" wait for the response. During this period, he believed he might have inadvertently caused a Denial of Service (DoS) to the system, especially as he was on-site in the company's basement. Fortunately, the system eventually responded, providing him with a massive dataset.

This anecdote serves as a practical demonstration of several key vulnerabilities:

  • Lack of Resource & Rate Limiting: The API allowed an unusually high pagination value without throttling or blocking the request.
  • Excessive Data Exposure: The API was willing to return thousands of records in a single response, indicating that it was not adequately filtering or restricting the amount of data exposed per request.
  • Potential for DoS: While not a successful DoS in this case, the prolonged response time and the attacker's fear of having taken the system offline highlight the potential for resource exhaustion if such requests were made maliciously or at scale.

This story underscores the importance of rigorous testing, even for seemingly innocuous parameters like pagination, and how a single oversight can expose significant amounts of data or lead to service disruption.

Defensive Implications

▶ Watch: Greatest 'oops' moment during an API pen test (26:50)

Securing APIs demands a proactive and multi-faceted approach, integrating "red team" insights into "blue team" defenses, effectively forming a "purple team" strategy. Tesauro's talk provides several crucial defensive implications:

  1. Comprehensive API Inventory (Posture Management): The first step is to know what you have. Organizations must maintain an accurate and up-to-date inventory of all APIs, including internal, external, public-facing, and deprecated versions. This inventory should detail their purpose, data sensitivity, and authentication/authorization mechanisms. Tools listed on Tesauro's shared API tools webpage can assist with this. Without this foundational understanding, securing the entire API surface is impossible.
  2. Deep Runtime Inspection and Anomaly Detection: Traditional WAFs are often insufficient for API security. Defenders need solutions capable of deep inspection into JSON/XML payloads to detect subtle anomalies, such as a valid token requesting another user's data (BOLA) or a request containing unexpected fields (Mass Assignment). Machine learning (ML) can aid in identifying unusual patterns in API traffic, but human analysts are still critical for context.
  3. Proactive and API-Specific Testing:
  • DAST and Fuzzing: Employ DAST tools that understand API specifications (OpenAPI/Swagger) and actively fuzz API endpoints with both valid and invalid data, including structural manipulations, to uncover vulnerabilities like lack of rate limiting or unexpected crashes.
  • Role-Based Testing: For APIs with multiple user roles, conduct thorough testing to ensure Broken Function Level Authorization and Broken Object Level Authorization are prevented. Test with user A attempting to access user B's data or administrative functions.
  • JWT Validation: Implement and rigorously test JWT generation and validation logic to prevent common misconfigurations and vulnerabilities. Referencing resources like the "JWT best practices" guide is essential.
  1. Robust Rate Limiting and Resource Management: Implement and thoroughly test rate limiting on all API endpoints to prevent brute-force attacks, resource exhaustion, and DoS. Ensure limits are appropriate and effective, not merely theoretical.
  2. Secure by Design Principles:
  • Minimize Data Exposure: Developers should explicitly whitelist data fields to be exposed in API responses, avoiding generic to_json calls that might leak sensitive information.
  • Strict Input Validation: Implement strong input validation and output encoding to prevent Injection attacks and Mass Assignment. Never trust user input; always treat it as data, not code.
  • Avoid API-Based User Login: Whenever possible, delegate user login to a human-facing web page with robust browser-based security controls (MFA, CAPTCHA). APIs should primarily handle tokens obtained through these secure login flows.
  1. Comprehensive Logging and Monitoring: Implement detailed logging for all API interactions, including authentication attempts, authorization failures, and unusual requests. Integrate these logs into a SIEM system for real-time monitoring, alerting, and forensic analysis. Insufficient logging leaves defenders blind to attacks.
  2. Address Security Misconfigurations: Regularly scan and audit API infrastructure for common misconfigurations, default credentials, and unpatched vulnerabilities. This includes securing API Gateways, load balancers, and underlying servers.

By adopting these defensive strategies, organizations can significantly enhance their API security posture, moving towards a resilient architecture that anticipates and mitigates the complex threats posed by modern API attack vectors.

Key Takeaways

  • APIs are the New Attack Surface: APIs are ubiquitous "data pipelines" and lack traditional browser-based security controls, making them prime targets for automated attacks.
  • Comprehensive API Inventory is Critical: Know what APIs you have, their purpose, and their data sensitivity (API Security Posture) as the foundation for any defense.
  • Deep Runtime Inspection is Essential: Traditional security controls are often insufficient. You need real-time, deep inspection of API traffic to detect subtle anomalies like BOLA or Mass Assignment.
  • Proactive & API-Specific Testing is Non-Negotiable: Leverage DAST, fuzzing, and role-based testing. Pay special attention to JWT implementation and structural attacks beyond just data manipulation.
  • Secure by Design Principles are Paramount: Developers must explicitly control data exposure, implement strict input validation, and establish robust rate limits to prevent common vulnerabilities.
  • Logging and Monitoring are Your Eyes and Ears: Implement comprehensive logging for all API interactions and integrate with monitoring systems to detect and respond to attacks promptly.

About the Speaker(s)

Matt Tesauro is an accomplished AppSec Engineer with a rich background as a programmer, whom he describes as a "reformed programmer." He is the CTO and co-founder of Defect Dojo Inc., and is deeply involved with OWASP, where he is considered one of its "dinosaurs" due to his long-standing contributions, including hosting the OWASP podcast. Tesauro is a fervent advocate for the Go programming language and is a dedicated Linux user, having exclusively used Linux since Windows 2000. Beyond his technical prowess, he is also a second-degree black belt in Meigu Kuan, a discipline he achieved three years prior to this talk. His diverse background provides him with a unique perspective on both developing and securing software.

Reviews

Dr. Zero (Offensive Security Researcher) — WEAK

Tesauro knows AppSec, but this session is just a recitation of the OWASP API Security Top 10. It is a perfectly competent introduction for absolute beginners. Anyone who has looked at API traffic in the last five years will learn nothing new.

Heather Calloway (CISO) — STRONG ACCEPT

Tesauro provides a practical breakdown of the OWASP API Top 10 that every product security team needs to internalize. It makes a clear case for why traditional web defenses fail against programmatic interfaces and is worth your application security leadership's time.

→ Top-rated talks at Swiss Cyber Storm 2024

All talks from Swiss Cyber Storm 2024