---
name: security-audit
description: >-
  Use before merging or publishing a web app, API, or site change to audit auth,
  secrets, tenant isolation/RLS, and trust boundaries with attacker scenarios
  and evidence states.
---
# Security Audit

Run an evidence-based pre-merge or pre-publish security audit covering auth, data isolation, secrets, input handling, and abuse vectors. Never exploit real user accounts, exfiltrate real data, or run destructive scans.

## 1. Attack-Surface Census
List every entry point in scope before auditing:
- Public routes, forms, and redirects
- Auth flows (sign-up, login, magic links, OAuth, password reset, session/cookie handling)
- API routes, server actions, webhooks, and background jobs
- Database tables, row-level security (RLS) policies, and file storage buckets
- Client-side JS bundles, environment config, and third-party/AI integrations

## 2. Core Security Checks
1. **Authentication & Sessions:** Verify secure cookies (`HttpOnly`, `Secure`, `SameSite`), token expiry, logout invalidation, and CSRF/CORS boundaries.
2. **Authorization & Tenant Isolation:** Test for IDOR and broken object-level access. For Supabase or similar BaaS, inspect RLS policies on every table and bucket—confirm `anon` and `authenticated` keys cannot read, update, or delete another user's records.
3. **Secrets & Client Leaks:** Check client bundles, public repos, env examples, and error payloads for API keys, service-role keys, tokens, or internal endpoints.
4. **Input Validation & Injection:** Check for XSS, SQL/NoSQL injection, SSRF, path traversal, open redirects, and unsafe file uploads.
5. **Abuse & Cost Controls:** Verify rate limiting on auth, email, and paid AI endpoints; confirm webhook signature verification; check client-supplied prices, credits, or roles cannot be tampered with.
6. **Transport & Headers:** Confirm HTTPS, security headers (CSP, frame protection, `X-Content-Type-Options`), and safe error messages (no stack traces in production).

## 3. Required Finding Format
List findings most severe first (Blocker / Major / Minor). Every finding must include:
- **Location:** exact file, route, table, or policy
- **Attacker scenario:** concrete step-by-step path an attacker would take
- **Counterevidence checked:** mitigating controls checked and confirmed absent or bypassable
- **Evidence state:** `Confirmed` (reproduced or proven in code/config), `Likely (not tested live)`, or `Needs manual check`
- **Recommended fix:** minimal, concrete remediation

## 4. Coverage Status & READY Handoff Block
State overall audit coverage explicitly as **Complete**, **Partial**, or **Not Assessed** per area, then close with the required four-field block:
- **Verified:** areas and controls audited and confirmed safe.
- **Unverified:** areas not inspected or needing live credentials/runtime access, and why.
- **Failed or skipped:** open security findings or skipped checks.
- **Also changed:** files or test fixtures touched (or "None — read-only audit").

Informal sign-offs do not count. Any code or config change after the audit requires a fresh block for the changed surface.
