
6 Next.js Server Action Security Patterns That Prevent Real Exploits in Production
React Server Components turned your frontend into a server attack surface. Most vulnerabilities now come from Server Actions. Here are 6 patterns that close the most common holes immediately. 1. Validate Every Server Action Input With Zod Server Actions receive untrusted input. Treat them like public APIs. Before ' use server ' ; export async function createJob ( formData : FormData ) { const title = formData . get ( ' title ' ); const company = formData . get ( ' company ' ); await db . jobs . create ({ data : { title , company } }); } After ' use server ' ; import { z } from ' zod ' ; const schema = z . object ({ title : " z.string().min(3).max(200), " company : z . string (). min ( 2 ). max ( 100 ), }); export async function createJob ( formData : FormData ) { const parsed = schema . safeParse ({ title : " formData.get('title'), " company : formData . get ( ' company ' ), }); if ( ! parsed . success ) { return { error : parsed . error . flatten () }; } await db . jobs . create ({ da
Continue reading on Dev.to React
Opens in a new tab




