Skip to the page

Mutations, APIs and the request layer · senior

Securing Server Actions and Server Functions

Every Server Action is a public HTTP endpoint: Next.js adds origin checks, encrypted ids and closure encryption, but you must authenticate, authorise, validate input and limit returned data inside each action, and patch framework CVEs quickly.

The notes

What you must know

  • Anyone can POST to an action without using your UI. Rendering the form only for admins is not a security boundary.
  • Framework protections: CSRF check comparing Origin with Host/X-Forwarded-Host (configure serverActions.allowedOrigins for proxies), 1 MB body limit, encrypted action ids and dead-code elimination of unused actions, encryption of captured closure variables.
  • Inside every action: get the user from the session (not from form data), check permission and ownership (findFirst({ where: { id, ownerId: session.user.id } })), validate input with zod (shape only), rate-limit sensitive actions, and return only what the UI needs.
  • Zod validation does not prove ownership: a well-formed id can belong to someone else.
  • A proxy matcher change or moving an action to another route can silently remove proxy coverage; never rely on proxy for action auth.
  • React2Shell (Dec 2025): CVE-2025-55182 (React) / CVE-2025-66478 (Next.js advisory), CVSS 10, unauthenticated remote code execution through Server Function payload decoding in Next 15.x/16.x App Router apps. Fix: upgrade (no workaround) and rotate secrets that may have leaked. Follow-up DoS and source-code-exposure CVEs came on 11 Dec 2025.
  • Since July 2026 Next.js publishes monthly scheduled security releases (plus out-of-band fixes); have an upgrade SLA. 16.4 experimental.agentUpgrade: "security" nudges you about vulnerable versions.

The red pen

Common traps: mistake → fix

  • Mistake: "Actions are private because they are not in an /api folder"

    Fix: they are POST endpoints.

  • Mistake: "zod validation is authorisation"

    Fix: it checks shape, not ownership.

  • Mistake: "The Origin check stops all attacks"

    Fix: it stops cross-site requests from browsers, not a logged-in user editing someone else's data.

Easy to hard

Questions interviewers ask, easy to hard

  1. Are Server Actions secure by default?
  2. How would you secure a "delete post" action?
  3. Why are unguessable action ids not enough?
  4. What did React2Shell teach us, and how fast did you upgrade?
  5. How do you prevent duplicate submissions?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview