Question presented to candidate: "Your team moved all mutations to Server Actions. What are the security risks, which ones does Next.js handle for you, and what must every action still do?"
What a strong answer should cover:
- Every exported action is a public HTTP endpoint: its id is in client code, and anyone can call it with a POST.
- So every action must authenticate and authorise the caller itself; hiding the button is not access control.
- Arguments and FormData come from the network: validate types and ranges on the server.
- Next.js adds protections: POST only, an Origin versus Host check against CSRF, encrypted non-deterministic ids, removal of unused actions from the client bundle, encrypted closure variables, a 1 MB default body limit.
- Keep return values minimal, because they are sent to the browser, and keep secrets out of action closures anyway.
Clarifying questions expected:
- "Where is authentication checked today: in the page or in the action?" β it must be in the action.
- "Is the app behind a reverse proxy?" β the Origin check may need
experimental.serverActions.allowedOrigins.
Code / implementation expected: Yes β an action with authentication, authorisation and validation.