FastAPI (Python 3.12) · CWE-352

FastAPI: CSRF & Cross-Origin Action Abuse

Stop third-party sites from submitting state-changing requests via ambient browser cookies. Applied specifically to FastAPI: Attach scoped Depends() auth resolvers to every path operation.

Primary AegisSec skill
web-protocol-auth-audit ->
Companion: owasp-web-audit
Coverage ledger tracking key
surface:fastapi::boundary:csrf-session::principal:current_user.id
ZAP 10202 Absence of Anti-CSRF Tokens check paired with SameSite state test
Risk boundary
// Unverified FastAPI path (CWE-352)
// Handler accepts client input without validating current_user.id or boundary invariants before sink.
Hardened guard
// Hardened FastAPI pattern (CWE-352)
// 1. Attach scoped Depends() auth resolvers to every path operation
// 2. Pair SameSite=Lax/Strict cookies with per-session anti-CSRF tokens or strict Fetch Metadata Origin validation.

Verification steps

  1. 01Seed coverage-ledger.json for every FastAPI route handling this boundary.
  2. 02Inspect the code trace from request input down to the persistence or egress sink.
  3. 03Confirm with paired User A vs User B requests (or staging baseline-vs-payload replay) via owasp-web-audit.