FastAPI (Python 3.12) · CWE-352

FastAPI: CSRF & Cross-Origin State Abuse (Code Remediation)

Implement fail-closed guards and safe data filters. Stop third-party pages from submitting authenticated state changes via ambient cookies. Tailored for 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::angle:remediation
ZAP 10202 Anti-CSRF token verification
Risk boundary
// Unverified FastAPI path (CWE-352 · Code Remediation)
// Handler accepts input without validating current_user.id.
Hardened guard
// Hardened FastAPI (CWE-352 · Code Remediation)
// 1. Attach scoped Depends() auth resolvers to every path operation
// 2. Pair SameSite cookies with anti-CSRF tokens or strict Fetch Metadata Origin validation.

Verification steps

  1. 01Seed coverage-ledger.json for every FastAPI handler touching CSRF & Cross-Origin State Abuse.
  2. 02Trace request parameters through current_user.id validation down to the sink.
  3. 03Verify with paired positive/negative evidence via owasp-web-audit.