Lion Cipher Lab

Enforce an OpenAPI contract at the edge: validate every request and response against the schema

Why it matters

Most API breaches are not clever. A client sends a field the developer never expected, such as role=admin, and the code saves it. Or an endpoint returns the whole database row, and the password hash rides along to every caller. Both bugs live in handler code that someone forgot to write carefully, and there are hundreds of handlers. An API contract written in OpenAPI turns 'what is allowed' into one document that a single piece of middleware enforces on every request and every response, so the next forgotten handler is caught at the edge instead of in an incident report. OWASP's API Security…

What you'll learn

Steps in this lab

  1. What an API contract is, in plain words
  2. Set up a folder and install jsonschema
  3. Write the contract: openapi.json
  4. Build the enforcer: contract.py
  5. Build the sloppy app and watch it leak: app.py
  6. Turn the contract on and send the same three requests
  7. Measure it: 34 requests, three ways
  8. Where schema validation stops: the four requests that got through
  9. Three gotchas: format, readOnly and the dollar sign
  10. What it costs: latency.py
  11. Judgment: when to validate responses, and how a pro runs this
  12. Clean up and what you built

Open the full interactive lab →