fastapi-security-patterns-v1Certifiedv1.0.0

FastAPI / Python security patterns

Always-on secure coding patterns for FastAPI / Python (safe; no dependency edits).

Protects against

Rule body

# FastAPI / Python security patterns

Safe, always-on code patterns that reduce security risk without changing your dependency graph.

These rules use ONLY pattern-level verbs (ALWAYS/NEVER). They MUST NOT prescribe dependency upgrades.

### CVE-2025-3248 — safe patterns

- Never expose remote code execution or validation endpoints without strong authentication.
- Never eval(), exec(), or dynamically run untrusted Python from HTTP payloads.

### CVE-2025-46814 — safe patterns

- Never use raw X-Forwarded-For as the sole authorization signal.
- Normalize and validate forwarded IPs with Python ipaddress and a trusted proxy configuration.

### CVE-2025-54365 — safe patterns

- Do not rely on regex middleware alone for injection defense.
- Treat Pydantic models as the primary request boundary and validation layer.

### CVE-2025-59034 — safe patterns

- Authorize every handler that accepts a resource identifier.
- Scope database queries through current_user (or equivalent); never fetch by id alone.

### CVE-2021-32677 — safe patterns

- Upgrade FastAPI to a release that closes the text/plain JSON bypass.
- Avoid cookie-only authentication without CSRF defenses on mutating routes.