Next.js · Cursor · Claude Code · v0
Next.js server actions are public endpoints: authorize every one
Server actions and route handlers can be called directly with a POST, not only from your UI. Why middleware/proxy checks aren't enough, and a small pattern that authorizes every mutation.
Why hiding the button isn't security
A function marked "use server" becomes an endpoint the browser calls with a POST. Next.js documents that server functions can be reached by direct POST requests, not just through your UI. So a delete button that only admins can see is irrelevant: anyone who can find the action can call it with any arguments.
Middleware is not a substitute. It's a convenient place for redirects, not the last line of defence: CVE-2025-29927 showed middleware checks could be skipped entirely with a crafted header on unpatched versions. Authorize where the data changes.
"use server";
export async function deleteProject(projectId: string) {
await db.project.delete({ where: { id: projectId } }); // anyone, any project
}"use server";
import { z } from "zod";
import { requireUser } from "@/lib/auth";
export async function deleteProject(input: unknown) {
const { projectId } = z.object({ projectId: z.string().uuid() }).parse(input);
const user = await requireUser(); // throws if signed out
const { count } = await db.project.deleteMany({
where: { id: projectId, ownerId: user.id }, // ownership in the query itself
});
if (count === 0) throw new Error("Not found");
}A checklist for AI-written actions
- Every action starts by resolving the user from the session, not from an argument.
- Every query that reads or writes a record includes the ownership or membership condition.
- Arguments are validated (zod or similar): types, sizes, enums.
- Prices, plans and roles come from the server, never from the form.
- Route handlers (app/api/*) get the same treatment, including GET handlers that return data.
Check it yourself
Sign in as user B, copy a request your app makes for user A's record from the network tab, and replay it with A's ID. It must fail. Do it for every create, update and delete.
Have every endpoint reviewed: Launch Check from $490
Questions
Are action IDs secret?
No. They're in the JavaScript your page ships. Assume anyone can call any action.
Does using Supabase with RLS solve this?
If the action queries Supabase with the user's session, RLS applies. If it uses a service-role client or another database, the action itself must check.
Updated 18 November 2026 · by Psychevus