What it is
API security is the set of controls that keep an HTTP or RPC API from being used in ways its owners did not intend: reading other people's data, writing fields that should be read-only, impersonating users, or consuming so much capacity that the service fails for everyone. The OWASP API Security Top 10 (2023) is the common reference:
- Broken Object Level Authorization (BOLA)
- Broken Authentication
- Broken Object Property Level Authorization (excessive data exposure + mass assignment)
- Unrestricted Resource Consumption
- Broken Function Level Authorization
- Unrestricted Access to Sensitive Business Flows
- Server Side Request Forgery (SSRF)
- Security Misconfiguration
- Improper Inventory Management
- Unsafe Consumption of APIs
Why it exists
Web pages used to hide most of the logic on the server. Modern apps push rendering to the client and expose objects and functions through APIs, which are easy to call with a script. The app's screens may only show your own orders and only the name field, but the API answers anything that is well-formed. Any rule the API does not enforce does not exist. Attackers also need only a normal account: most of the top risks are abuses of authorized access, not break-ins.
How it works
Object-level authorization (API1). Every id in a path, query or body is attacker-controlled. The service that loads the object checks it against the caller (owner, tenant, team) and answers 403 or 404. Make it structural: a repository method that always filters by tenant, or row-level security in the database, rather than a check each handler must remember.
Authentication (API2). Throttle and monitor login, password reset and token endpoints per account and per source; prefer passkeys or MFA; check passwords against breach lists. Validate tokens fully: signature with a pinned algorithm, iss, aud, exp. Do not put long-lived API keys in URLs (they end up in logs) or in mobile app binaries.
Property-level authorization (API3). Responses go through an explicit output model with an allowlist of fields; never serialize the database row. Requests bind to an explicit input model; never bind the body onto the persistence model. Decide per field whether this caller may read or write it (users may change name, not role).
Resource consumption (API4). A token bucket per API key or per user at the edge; separate, tighter limits on expensive or sensitive operations (login, exports, search); maximum page sizes, request body sizes, upload sizes, query depth for GraphQL, and timeouts. Return 429 with Retry-After.
Function-level authorization (API5). Admin and internal endpoints check roles on the server, not by being hidden from the UI. Deny by default.
Input validation. Validate against a schema (OpenAPI or JSON Schema) at the edge: types, lengths, formats, enums, and additionalProperties: false. Validate again in the service. Validation is about shape; it does not replace authorization. Use parameterized queries regardless.
Transport. TLS 1.2 or 1.3 everywhere, HSTS on browser-facing hosts, and encryption on internal hops too (re-encrypt from the gateway, or mTLS in a mesh; see Zero Trust).
When to use it
Always, for any API reachable by anything you do not fully control: public APIs, mobile and SPA backends, partner APIs, and internal APIs (internal callers get compromised too).
When not to
No API is exempt. What varies is depth: an internal read-only metrics endpoint needs less than a payments API. Avoid controls that only look like security: obscurity (undocumented endpoints), client-side checks, and IP allowlists as the only control.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Schema validation at the gateway | Junk rejected early, one place to enforce shape | Schemas must stay in sync with the service |
| Per-key limits at the edge | Abuse rejected before it costs capacity | Picking limits per plan, shared state across gateway nodes |
| Response DTOs instead of serializing models | No accidental field leaks | More mapping code |
| Row-level security in the database | Tenant isolation even when code forgets | Harder debugging, query planning surprises |
| Returning 404 instead of 403 | Hides which ids exist | Harder for legitimate clients to debug |
Alternatives
There is no alternative to authorization and validation, but there are choices of where and how: an API gateway versus a service mesh versus in-process middleware for edge checks; policy engines (OPA, Cedar) versus code for authorization; a WAF or bot-management product in front of the gateway for volumetric and known-signature attacks (useful, but it cannot see BOLA or mass assignment, which look like normal traffic).
Failure modes
- Only the gateway checks: object and field rules need business data the gateway does not have.
- Old versions left running (API9):
/v1without the fixes that/v2has, or a forgotten staging host with production data. - Global-only rate limits: one client exhausts the shared budget and legitimate users get 429s.
- Limits per IP only: botnets and cloud ranges spread requests below the limit.
- Verbose errors: stack traces and "user not found" vs "wrong password" help attackers.
- SSRF (API7): an endpoint that fetches user-supplied URLs reaches internal metadata services. Allowlist destinations.
- Trusting third-party APIs (API10): data from partners is input too; validate it.
In production
Keep an inventory of every API, version, host and owner, generated from code or gateway configuration. Generate schemas from code and test that unknown fields are rejected. Write authorization tests that try another tenant's ids on every endpoint. Log authorization failures and alert on spikes (enumeration shows up as many 403/404s from one caller). Rate limit with distributed counters (Redis or the gateway's built-in store), and return Retry-After. Run dependency and configuration scanning in CI, and turn off debug endpoints and CORS wildcards in production.
Common misconceptions
- "Authenticated means authorized." A valid token says who is calling, not whether they may touch object 1002.
- "The app only calls endpoints the right way." Attackers call your API without your app.
- "HTTPS makes the API secure." TLS protects data in transit; it does nothing against a valid user asking for someone else's data.
- "A WAF covers the OWASP API Top 10." WAFs catch signatures and volume. Most API flaws are logic flaws that look like normal requests.
- "Rate limiting is a performance feature." It is also a security control against scraping, stuffing and cost attacks.
Interview angle
Interviewers want controls placed in a design, not a list recited. Say where tokens are validated, where object-level checks live, how responses are shaped, and how limits are keyed (per API key, per user, per endpoint cost). Mention BOLA by name, explain mass assignment, and show you know a WAF is not enough. Bonus points for structural fixes: tenant-scoped repositories, row-level security, generated schemas, and authorization tests across tenants.
Model assumptions
Steps 2–5 and 8 are a scripted illustration, not a simulation: object ids, response fields, schemas and credentials are drawn as hand-placed packets with illustrative durations (12 ms to the gateway, 4 ms between internal components). Steps 1, 6, 7 and 9 use the simulation: app users at 100 requests per second and an attacker at 600 requests per second from step 6 (Poisson arrivals), a gateway with 1 ms of work, an orders API with 16 workers, 30 ms mean service time (lognormal, cv 0.3) and room for 40 waiting requests, and a database with 24 connections and 5 ms reads. The API holds a worker for about 37 ms per request, so it serves roughly 430 requests per second; beyond that its queue fills and it answers 503. The per-key limit is a token bucket of 10 requests per second with a burst of 20, drawn as its own lane in front of the gateway because the engine's gateway has a single shared bucket. Numbers are illustrative, not benchmarks of any product.