Server Action security
Treating every Server Action as a public HTTP endpoint that anyone can call with any arguments.
An unchecked action lets any visitor change or read data that belongs to someone else.
In more detail
Hiding a button does not protect an action: its ID can be found and called directly. Inside every action, check the session (authentication), check that the user may touch this record (authorization) and validate every argument, for example with Zod. Return safe error messages, never raw exceptions.
Related terms
- Server Functions — Async functions marked with "use server" that run on the server but can be called from client components, for example as a form action.
- authentication — Establishing who a request represents, for example by checking a password, a session cookie or a signed token.
- authorization — Deciding whether an already identified caller may perform a particular action on a particular resource.
- Zod — A TypeScript library for declaring validation schemas that check data at run time and also produce matching static types.
Taught in
- Optimistic UI: useOptimistic Rollbacks & Transitions — Next.js 15 & Modern App Router Architecture
- Server Action Security: Zod Validation & Auth Gates — Next.js 15 & Modern App Router Architecture
- Streaming Endpoints: Server-Sent Events & NDJSON Feeds — Next.js 15 & Modern App Router Architecture
- Edge Middleware: Auth Verification & Route Matchers — Next.js 15 & Modern App Router Architecture