Server Action Auth

Server actions that write data, send something out or call an AI model, with no auth check

warningSecurityserver-action-auth

Severity depends on context. Info when auth middleware covers the pages the action is posted to, and for a model-only action when rate limiting is detected in middleware.

Why this matters

Server actions are public HTTP endpoints: anyone can POST to one without ever loading your page. With no check inside the action, a stranger can change your data, send mail or requests from your server, or spend your AI credits.

Example

Flaggedapp/actions/posts.ts
"use server";

export async function deletePost(id: string) {
  await db.post.delete({ where: { id } });
}
Fixedapp/actions/posts.ts
"use server";

import { auth } from "@/lib/auth";

export async function deletePost(id: string) {
  const session = await auth();
  if (!session?.user) throw new Error("Unauthorized");

  await db.post.delete({
    where: { id, authorId: session.user.id },
  });
}

How to fix

Check the user's session at the top of every server action that writes data, sends mail or requests, writes files or calls a model, and scope what it does to that user. A public action that calls a model needs a rate limit instead. Middleware alone lowers the finding to info but doesn't clear it: an action is a POST to a page, and middleware lets public pages through.

Reference

In the output
Findings carry "ruleId": "server-action-auth" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line server-action-auth
Silence a whole file
// prodlint-disable server-action-auth at the top of the file
How it works
Reads the syntax tree, with a text fallback for files that don't parse. Source on GitHub