Home / patterns

Server Actions with no auth check inside them

Quick answer: In Next.js apps, AI tools often put the login check on the page and assume the Server Actions on that page are protected too. They're not. The Next.js docs say a Server Action can be called with a direct POST request, so every action has to check who the user is and what they're allowed to change.

Last updated November 13, 2026

Steps

  1. Search for "use server" and list every exported action: create, update, delete, invite, checkout, admin tools.
  2. At the top of each action, get the current user from the session on the server and return an error if there isn't one. Don't trust a userId passed in from the form.
  3. Then check authorization: does this user own the record, or have the role, for this specific change?
  4. Validate the input (for example with a schema) and only update the fields you expect.
  5. Return only what the UI needs, not full database rows. Next.js also warns that values captured in closures inside actions are sent to the client and back, so don't capture secrets.
  6. Rate limit sensitive actions such as sending email, inviting users or calling AI models.
  7. Test it: sign in as a regular user and replay an admin action's request with a different ID. It should fail.

Why it matters

The Next.js data security guide says Server Actions are reachable by direct POST requests even when not imported elsewhere, and that a page-level auth check doesn't extend to the actions defined in it. OWASP lists broken function level authorization (API5:2023) as a top API risk: regular users reaching admin functions because the server never checks.

Sources

Next.js Docs: Data Security (Server Actions) — https://nextjs.org/docs/app/guides/data-security

Next.js Docs: Authentication — https://nextjs.org/docs/app/guides/authentication

OWASP API Security Top 10 2023, API5 Broken Function Level Authorization — https://owasp.org/API-Security/editions/2023/en/0xa5-broken-function-level-authorization/

OWASP Authorization Cheat Sheet — https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html

Related patterns

Found a problem you'd rather not fix yourself?

Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.

Get it fixed by StorenTech

Vibe Security Weekly

One email a week with new failure patterns and how to fix them.

By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.