API Security
Protect APIs with strong authentication, per-object authorisation, schema validation and rate limiting.
IntermediateSecure CodingApplicationIdentity
Where it fits in the lifecycle
- Plan
- Code
- Build
- Test
- Release
- Deploy
- Operate
- Monitor
- Code Static analysis, secret detection and secure coding practices.
- Test Dynamic testing, integration security tests and security gates.
- Operate Runtime security, secrets rotation and configuration reconciliation.
Overview
API risk concentrates in authorisation: object-level access, function-level access and property-level exposure. Schema validation and rate limiting handle the rest of the common cases.
Why it matters
APIs expose business logic directly, and broken object-level authorisation is consistently the top API weakness.
How it works
- 01Authenticate with short-lived tokens and validate claims server-side.
- 02Authorise every object access against the caller's identity.
- 03Validate requests and responses against a schema.
- 04Apply rate limits per identity, not only per IP.
Common tools
OWASP ZAPSemgrepKongKubernetesPythonGitHub
Implementation examples
pythonObject-level authorisation
# Unsafe: trusts the client-supplied tenantinvoice = db.get_invoice(request.json["invoice_id"]) # Safe: scope the lookup to the authenticated tenantinvoice = db.get_invoice( invoice_id=request.json["invoice_id"], tenant_id=claims["tenant_id"],)if invoice is None: abort(404)Best practices
- Derive tenancy from token claims.
- Return 404 rather than 403 for objects outside scope.
- Rate limit per identity.
Common mistakes
- Checking authentication but not per-object authorisation.