This skill should be used when the user asks to "add an API route", "handle user input", "write a webhook", "add authentication", "security review", "security audit", "is this secure", "validate input", "add rate limiting", "add CSRF", "RLS", "env vars", "email template", "stripe integration", "payment flow", "send email", or before any code that touches auth, user data, API boundaries, or external inputs . The unified security contract.
TL;DR: 16 security invariants. Every API route, user input handler, and data boundary must satisfy these.
server-only imports — All sensitive modules (DB clients, API keys, scoring, pipeline) use import "server-only". Client components never import server modules.process.env access routed through getServerEnv() / getPublicEnv() from src/lib/env.ts. No direct process.env usage anywhere.createAdminClient()) used for writes; cookie client for reads.verifyCronSecret() — Pipeline and cron routes verify CRON_SECRET header. Returns JSON error if missing/invalid.(dashboard)/ has a corresponding entry in middleware.ts config.matcher. Missing routes = silent auth bypass (sessions not refreshed → RLS sees anon role).constructEventWithSecret() verifies signature + checks replay window. Webhook secret in STRIPE_WEBHOOK_SECRET env var.references/known-limitations.md).escapeHtml() — All user-provided strings in email templates escaped via shared escapeHtml() from src/lib/email.ts. Prevents XSS in weekly digest, alert emails, welcome emails.res.json() fails. Every route has a single outer try/catch.src/lib/env.ts (validation) + Vercel dashboard + GitHub Secrets (for Actions). All three must stay in sync.@optional comments in env.ts.npm audit --audit-level=high runs in CI and Husky pre-commit hook. Block on high/critical vulnerabilities. Stripe API version pinned. npm overrides for unpatched transitive CVEs.Verify all of:
(dashboard)/, middleware matcher updatedVerify all of:
Verify all of:
constructEventWithSecret() — never trust unverified payloadsgetServerEnv()Verify all of:
escapeHtml() from src/lib/email.ts<script>alert(1)</script> in name, ticker| File | Guards | Check When |
|---|---|---|
src/lib/env.ts | Env var validation (getServerEnv/getPublicEnv) | Adding env vars |
src/middleware.ts | Session refresh, route matching | Adding dashboard routes |
src/lib/verify-cron.ts | CRON_SECRET header check | Adding cron/pipeline routes |
src/lib/stripe/server.ts | Stripe client, apiVersion pin | Stripe integration changes |
src/lib/email.ts | escapeHtml, email templates | Email template changes |
See references/security-audit-history.md for the security audit history template.
See references/known-limitations.md for the known limitations template.