Search Psychevus

12 results available.
↑ ↓ to navigate ↵ to open · esc to close

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.

Short answerTreat every server action like a public API route: check the session and the caller's right to the specific record inside the action itself, every time, and never trust an ID, role or price passed as an argument. Checks in middleware (proxy in Next.js 16) or in the page that renders the button don't protect the action, because the action can be invoked without them.

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.

A vulnerable action, as generated
"use server";
export async function deleteProject(projectId: string) {
  await db.project.delete({ where: { id: projectId } });   // anyone, any project
}
Authorized: who is calling, and may they touch this record?
"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

Reading about a flaw is the easy part. A Launch Check finds every one of these in your app, with evidence and a fix prompt for each, in two business days.

Get a fixed quote

Related

YOUR VISIT, YOUR CHOICE

Privacy, by intention.

You decide what stays on your device. You can change your choice at any time.

Essential

Saves your privacy choice. Administrator sign-in uses a secure session cookie.

Always on
Full privacy notice ↗