Next.js Server Actions are public endpoints: 6 checks before you ship an AI-built app
Next.js Server Actions feel private. You write a function with "use server", call it from a form, and the code runs on the server. AI tools generate them constantly. But each one becomes a public HTTP endpoint that anyone can call, with or without your form.
What that means
- The browser sends a POST request with an action id. Someone who finds that id can replay the request from outside your UI.
- Hiding the button, or checking a user in the component, protects nothing. The function itself must check.
- Arguments come from the client. Treat every argument as untrusted input, including ids and prices.
6 mistakes to check
- No auth check inside the action. Read the session on the server, and reject if there is none.
- Trusting a user id passed as an argument. Take the id from the session instead.
- No ownership check.
deletePost(id)should confirm the post belongs to the caller. - No input validation. Validate with a schema before touching the database.
- Using a service key inside the action without any permission check, so the database cannot help.
- Returning more than needed. Whole rows, tokens or internal errors sent back to the client.
The unsafe fixes
- Wrapping the check in the front end only.
- Switching to the service role key to silence a policy error.
- Reading prices or roles from form fields.
The safe pattern
Start every action with the same three steps: get the session, validate the input, check the caller may act on that record. Put them in one helper so a new action cannot forget them. Keep row level security on as a second layer.
A quick test
Open DevTools, Network, submit your form, and copy the request. Replay it signed out, then as another user with a changed id. If it works, the action is open.
ProofForge at proofforge.live runs a free public-side scan of AI-built apps. It never signs in, so it cannot call your actions as a user and will not tell you they are safe. It does check what a visitor can reach and see, and for Supabase apps there is a free two-account test using two of your own test accounts.