OWASP API Security & Secret Management
Defend microservices against the OWASP API Security Top 10, eliminate BOLA/IDOR vulnerabilities, and manage enterprise secrets with Vault.
Microservices architecture inherently multiplies your system's attack surface: instead of defending one monolithic application with a single entry point, you now operate dozens of microservices exposing hundreds of REST and gRPC endpoints.
Understanding the OWASP API Security Top 10 is mandatory for every senior backend engineer.
01OWASP API #1: Broken Object Level Authorization (BOLA)
Also known as Insecure Direct Object Reference (IDOR), BOLA is consistently ranked by OWASP as the #1 most severe and prevalent API vulnerability in the world.
The Attack Vector:
A developer writes this seemingly safe Spring controller:
// CRITICAL VULNERABILITY: BOLA / IDOR!
@GetMapping("/api/v1/invoices/{invoiceId}")
public Invoice getInvoice(@PathVariable Long invoiceId) {
return invoiceRepository.findById(invoiceId).orElseThrow();
}- Alice logs in legitimately and views her invoice:
GET /api/v1/invoices/1001. - Alice is authenticated with a valid JWT token.
- Alice opens browser developer tools and changes the URL to:
GET /api/v1/invoices/1002(which belongs to Bob!). - Spring Security checks: "Is Alice authenticated?" ➔ YES.
- The controller executes
findById(1002)and streams Bob's private tax invoice, home address, and financial charges directly to Alice.
The Defense: Mandatory Ownership Verification
Never query entities by object ID alone. Always bind the database query to the authenticated user's identity:
@GetMapping("/api/v1/invoices/{invoiceId}")
public Invoice getInvoice(@PathVariable Long invoiceId,
@AuthenticationPrincipal Jwt jwt) {
String currentUserId = jwt.getSubject();
// Query binds BOTH the entity ID AND the authenticated customer ID!
return invoiceRepository.findByIdAndCustomerId(invoiceId, currentUserId)
.orElseThrow(() -> new ResourceNotFoundException("Invoice not found: " + invoiceId));
}If Alice requests Bob's invoice ID, the database query returns empty, and the API returns 404 Not Found. Alice cannot even determine whether invoice #1002 exists.
Loading the rest of the lesson…