Card 10/ 10

RecapDifficulty: Advanced1 min

Recap: Protecting an API

Check the object, accept only known fields, validate every value, publish your limits, and do not lean on CORS.

Five design rules close the risks behind most API breaches.

  • The OWASP API Security Top 10 maps the risks; five are settled by design.
  • Object-level authorisation: scope every lookup to the caller, answer 404, test with two accounts.
  • Mass assignment and exposure: name the fields each operation accepts and returns.
  • Input validation: check every value against the contract at the edge, and limit everything that grows.
  • Rate limits: 429 with Retry-After, and headers that show the limit and what is left.
  • CORS: an allow-list of origins, never a reflected one with credentials.
  • CORS is not access control: only browsers enforce it.
The five risks against the four questions
RiskWhat goes wrongThe fixHow to test
Object level authorisationAnother user's object by idScope lookups to the callerTwo accounts, swapped ids
Mass assignment and exposureFields set or seen that should not beAllow-lists in and outExtra fields sent and sought
Input validationBad or huge values reach the codeSchema checks and size limitsBoundary and oversized values
Resource consumptionOne client exhausts the APIRate, size and page limitsLoad past the limit
CORSAny site reads responsesAn origin allow-listUnlisted and null origins