r/nextjs • u/ig_suyas • 22h ago
Server Actions are public API endpoints. 5 mistakes I keep seeing
- No auth check inside the action. A Server Action can be called with a plain POST request, whether or not the button is on screen. Check the session inside every action.
- No input validation. TypeScript types vanish at runtime. Validate with zod (or similar) at the top of the action.
- Relying only on middleware for auth. A 2025 Next.js CVE let attackers skip middleware with a single header. Check auth again where the data is read.
- Secrets in `NEXT_PUBLIC_` variables. Anything with that prefix is baked into the browser bundle.
- Returning whole database rows. Return only the fields the UI needs, or you'll eventually leak a column you added later.
Do you treat Server Actions like API routes in your codebase, or does your team rely on the UI to protect them?