Skip to content

10. API security: API Security QA

The most common serious API flaw, broken object level authorization (OWASP API1), looks like a perfectly normal request to a scanner: a logged-in user asking for an id. Finding it needs two real users and knowledge of which object belongs to whom. k11 API Security QA generates those tests from your OpenAPI spec, runs them as your test users against a test environment, and judges your existing scanner results for the release decision.

The checks

Check OWASP API Top 10 (2023) What it proves
bola API1 bob can't read, change or delete alice's object; a control request proves alice can
auth API2 every operation the spec marks as secured rejects missing and invalid credentials
mass_assignment API3 client-sent role, isAdmin, balance, price, and server-set fields from the response, are ignored, not stored
data_exposure API3 no password hashes, tokens or keys in responses; flags fields the spec doesn't document
bfla API5 normal users can't call admin-only operations
headers API8 CORS doesn't trust any origin with credentials; hardening headers; no version leaks
errors API8 malformed input gets a clean 400, not a stack trace or a 500
rate_limit API4 repeated requests are throttled (opt-in)

Control requests make results honest. Before testing whether bob can read alice's order, the tool checks that alice can. If she can't (the test resource wasn't created, the token expired), bob's 404 proves nothing, and the result is reported as inconclusive, not passed.

Configure

Environments and auth profiles come from .qa-mcp/api-test.yaml (Chapter 9). Security settings are in .qa-mcp/security.yaml (k11-api-security-qa-mcp init writes a starter):

identities:
  alice: { auth: alice }        # TEST users only
  bob:   { auth: bob }
  admin: { auth: admin }        # optional
resources:                      # an object alice owns, for each path with an id
  "/accounts/{id}":
    create: { call: POST /accounts, body: { name: QA account }, save: "$.id" }
admin_paths: ["/admin/**"]      # operations tagged "admin" count too
checks: [auth, bola, bfla, mass_assignment, data_exposure, headers, errors]
sarif: ["security-reports/*.sarif"]

The first normal identity owns the test objects; the others try to reach them. A resource's create call is made as the owner, and the object is deleted afterwards unless delete: false is set (for APIs without a DELETE). A resource matches deeper paths too: /orders/{id} also provides the id for /orders/{id}/cancel.

Scanner results, judged for a release

Most teams already run scanners (Semgrep, CodeQL, Trivy, Gitleaks, Checkov, ZAP…) and drown in their output. API Security QA reads their SARIF and counts only what matters for this release:

  • New findings only. Run k11-api-security-qa-mcp baseline on main; later runs compare with .qa-mcp/security-baseline.json, so only findings a change introduced count.
  • Accepted risks expire. .qa-mcp/security-accepted.yaml lists accepted findings, each with an owner, a reason and an expiry date. When the date passes, the finding counts again.
accepted:
  - rule: python.lang.security.audit.md5-used
    path: app/legacy/checksum.py
    owner: "@security-lead"
    reason: legacy file checksum, not used for passwords
    expires: 2026-12-31

Run it

In Claude Code, /security-check confirms the environment and that the identities are test accounts, runs the checks, and explains each finding: what an attacker could do, the exact request that proved it (as which user, with which status) and the fix.

In CI:

k11-api-security-qa-mcp run --env ci --fail-on never
Option Default
--env NAME from api-test.yaml; production-like names are refused
--checks a,b the list in security.yaml
--no-api / --no-scanners run both
--report-dir PATH .qa-mcp/security-report
--fail-on LEVEL high (critical or high); also critical, medium, never

Safety

  • Never production. Environments named like production are refused, with no override. Testing production needs explicit authorisation and a scoped engagement, not a CI job.
  • Writes only where allowed. Checks that create or change data run only where API Functional QA allows writes; elsewhere they are reported as not run.
  • Credentials come from ${ENV:NAME} and never appear in reports; requests never leave the environment's host.

Evidence for the gate

security-report.json is the security kind.

Rule Outcome
security.critical, security.high block: API test findings, or new scanner findings, at that severity
security.acceptance_expired needs a person: an accepted risk passed its expiry date
security.not_run needs a person: the run was refused or failed
security.medium condition: plan a fix
security.inconclusive note: tests that couldn't prove a result

Changes to auth, permission, middleware, route and controller code, dependency manifests and Dockerfiles require security evidence. In the K11 Shop demo (Chapter 17), a "simpler" order lookup that dropped the owner check was blocked with "API1:2023 bob can read an object that belongs to alice (GET /orders/{id})".