| name | security-review |
| description | Security checklist for code review—validates auth, input validation, secrets, database safety, Stripe integration, XSS prevention, and dependencies |
| disable-model-invocation | true |
Security Review
Audit defensively. Every mutating Server Action authenticates the caller and verifies ownership before it touches data; every external boundary — Stripe webhooks, user input, env access — is validated before it's trusted. Work the checklist top to bottom and treat any unchecked box as a blocker, not a suggestion.
Checklist
Authentication & Authorization
import { auth } from '@/lib/better-auth/auth';
import { headers } from 'next/headers';
const session = await auth.api.getSession({ headers: headers() });
if (!session) return { success: false, error: 'Unauthorized' };
if (resource.userId !== session.user.id) {
return { success: false, error: 'Forbidden' };
}
Input Validation
Environment Variables
Database (Prisma)
catch (e) { return { success: false, error: e.message }; }
const [error] = await safePromise(db.subscription.delete({ where: { id } }));
if (error) {
console.error('[cancelSubscription]', error);
return { success: false, error: 'Failed to cancel subscription' };
}
Stripe
XSS & Injection
Dependencies
Vulnerability Reference
| Vulnerability | Mitigation in this project |
|---|
| IDOR | Ownership check after session validation |
| Secret exposure | src/env.ts + .env.local (gitignored) |
| Mass assignment | Zod schema whitelists allowed fields |
| XSS | React escapes by default; no dangerouslySetInnerHTML |
| CSRF | Better Auth manages session cookies |
| Webhook spoofing | Stripe signature verification |
| Injection | Prisma parameterised queries |
Quick Audit Commands
grep -rn "process\.env\." src/ | grep -v "src/env.ts"
grep -rn "dangerouslySetInnerHTML" src/
grep -rn " as any" src/
bun audit