Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

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 anyon

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

  1. No auth check inside the action. Read the session on the server, and reject if there is none.
  2. Trusting a user id passed as an argument. Take the id from the session instead.
  3. No ownership check. deletePost(id) should confirm the post belongs to the caller.
  4. No input validation. Validate with a schema before touching the database.
  5. Using a service key inside the action without any permission check, so the database cannot help.
  6. 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.

Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.