API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. API Security
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. API Security

OWASP API Security Top 10

The Open Web Application Security Project (OWASP) maintains a standard awareness document for the most critical security risks to web applications. Recognizing the unique threats APIs face, they released a dedicated API Security Top 10.
Understanding these vulnerabilities is crucial for any API developer. Below is a summary of the key risks (based on the 2023 release).

1. Broken Object Level Authorization (BOLA)#

The Problem: Often called IDOR (Insecure Direct Object Reference). It happens when an API exposes a reference to an object (like id in the URL) and doesn't check if the verified user actually has permission to access that specific ID.
Example: User A (id: 100) changes the URL from /orders/100 to /orders/101 and can see User B's order.
Fix: Always check: if (order.owner_id != currentUser.id) return 403;

2. Broken Authentication#

The Problem: Mechanisms to verify user identity are weak.
Examples: Allowing weak passwords, not having rate limiting on login (brute force), sending tokens in URLs, or valid tokens remaining active after logout.
Fix: Use standard OIDC flows, enforce strong passwords, implement MFA (Multi-Factor Authentication).

3. Broken Object Property Level Authorization#

The Problem: An API endpoint exposes more data fields than the client needs (Excessive Data Exposure) or allows the client to update fields they shouldn't (Mass Assignment).
Example: An endpoint returns the full User object including password_hash and is_admin, even if the UI only needs username. Or, a PUT /profile allows a user to send {"is_admin": true} and the code unknowingly saves it.
Fix: Return only necessary fields (Response DTOs). detailed whitelisting of input fields.

4. Unrestricted Resource Consumption#

The Problem: The API doesn't limit the resources a client can use, leading to Denial of Service (DoS).
Examples: Missing rate limits, allowing huge page sizes in pagination, or complex graphQL queries that lock the DB.
Fix: Implement Rate Limiting (e.g., 60 req/min), limit payload sizes, and set timeout limits.

5. Broken Function Level Authorization#

The Problem: Relying on the client app to hide administrative functions instead of enforcing checks on the server.
Example: An endpoint DELETE /api/users exists. The UI hides the button for normal users, but a hacker finds the URL and calls it directly.
Fix: Check roles/permissions in the code for every controller method. @PreAuthorize("hasRole('ADMIN')").

6. Unrestricted Access to Sensitive Business Flows#

The Problem: Abusing legitimate business workflows in a way that harms the business (automation/bots).
Example: Scalping bots buying all tickets in 1 second.
Fix: Bot detection, CAPTCHA for sensitive flows.

7. Server Side Request Forgery (SSRF)#

The Problem: The API fetches a remote resource based on a user-supplied URL without validation.
Example: POST /image-upload accepts a URL. Attacker sends http://localhost:8080/admin. The server fetches it (bypassing the firewall) and returns the content.
Fix: Whitelist allowed domains. Do not allow calls to internal networks or localhost.

8. Security Misconfiguration#

The Problem: Defaults are not secure.
Examples: Verbose error messages (stack traces) leaking info, unnecessary HTTP verbs enabled, missing security headers (CORS, CSP), or unpatched dependencies.
Fix: Hardening procedures, automated scanning, disable debug mode in production.

9. Improper Inventory Management#

The Problem: "Zombie" APIs. You can't secure what you don't know exists.
Examples: Old API versions (v1) still running without patches while v3 is live. Staging environments exposed to the public.
Fix: Maintain an accurate inventory (OAS), decommission old versions.

10. Unsafe Consumption of APIs#

The Problem: Trusting data received from 3rd party APIs blindly.
Example: Your API calls a weather service. That service gets hacked and sends malicious SQL injection payloads back to you, which you save to your DB.
Fix: Validate/Sanitize all input, even from "trusted" external APIs.

Key Takeaways#

BOLA (IDOR) is the #1 API vulnerability. Always check ownership.
Authentication and Authorization flaws are the root cause of most breaches.
Trust Nothing: Not user input, not internal services, not 3rd party APIs.
Next Step: All these protections are useless if the data is stolen in transit. Let's ensure the pipe is secure with Encryption and HTTPS.
Modified atΒ 2025-12-29 04:30:23
Previous
JSON Web Tokens (JWT)
Next
Encryption and HTTPS
Built with