Common API security issues (OWASP API Top 10)
What are the most common API security vulnerabilities (the OWASP API Security Top 10), and how do you prevent them?
TL;DR
The number one API vulnerability is broken object-level authorization (BOLA): the API checks that you're logged in but not that the object you asked for belongs to you, so changing /orders/123 to /orders/124 shows someone else's order. Other top risks are broken authentication, exposing or accepting too many fields (mass assignment), no rate limiting, broken function-level authorization (regular users reaching admin endpoints), and SSRF. The fixes: authorize every object access on the server, validate input against a schema, return only the fields the client needs, and rate-limit.
Key points
- BOLA / IDOR: scope every query by the current user or tenant:
WHERE id = $1 AND owner_id = $2. Random UUIDs make guessing harder but don't replace the check. - Mass assignment: don't bind request bodies straight to models. A user sending
"role": "admin"must not become admin. Use explicit allow-lists or DTOs. - Excessive data exposure: serialize response DTOs, never whole database rows (password hashes, internal flags).
- Injection: use parameterized queries; never build SQL from strings.
- SSRF: when the server fetches user-supplied URLs, allow-list hosts and block internal IP ranges and cloud metadata endpoints.
- Plus: TLS everywhere, secrets out of code, security headers, dependency scanning, and logs that never contain tokens.
Example
// Vulnerable: any logged-in user can read any invoice
const invoice = await db.invoice.findUnique({ where: { id } })
// Fixed: scoped to the caller's organization
const invoice = await db.invoice.findFirst({ where: { id, orgId: session.orgId } })
if (!invoice) throw new NotFoundError() // 404, so you don't reveal it existsCommon follow-ups
- Should a forbidden object return 403 or 404? Often 404, so attackers can't tell which IDs exist.
- Where should authorization live? In one central, tested layer (policies or middleware), not scattered
ifstatements.
What interviewers look for
Tip
Lead with object-level authorization and a concrete fix, then cover input validation, output filtering and rate limiting.
- Red flag: "we use JWT, so the API is secure." Authentication isn't authorization.