Skip to main content
rule CX Codex

server-auth-actions — Claude Code rule: what it does, install

The server-auth-actions rule puts authentication and permission checks inside every Server Action. Use it to guard server mutations that callers can invoke directly.

MIT ★ 4,719 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/server-auth-actions.md
Open on GitHub

What server-auth-actions does

The rule treats functions marked with "use server" as public entry points, much like API routes. Each Server Action should validate its input, check the session, confirm the caller’s permissions, and only then change stored data. The examples use verifySession, unauthorized, and zod schemas.

A middleware, layout guard, or page check does not protect the action by itself because the function may be called directly. Deleting a user therefore needs a check for an administrator or that same user, while profile updates must belong to the signed-in account. In Claude Code, install the rule at .claude/rules/server-auth-actions.md; Codex is also listed as a supported platform.

What it helps with

  • secure a Server Action against unauthorised calls
  • stop users from deleting other accounts
  • allow profile edits only for the owner
  • validate mutation input before writing data

Example prompts for the agent

  • Review every Server Action in this project and put the session check inside each function.
  • Rewrite user deletion so an administrator or the account owner can perform it.
  • Add zod validation before the profile update and reject edits to another user’s profile.

How to install server-auth-actions

Manually: put the files in place

.claude/rules/server-auth-actions.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about server-auth-actions

How do I install server-auth-actions in Claude Code?

Add the rule file at .claude/rules/server-auth-actions.md.

What does server-auth-actions do?

It requires each Server Action to validate input, authenticate the caller, and check permissions before performing a data mutation.

Why must authentication happen inside the Server Action?

A Server Action can be invoked directly, so middleware, layout guards, and page-level checks do not secure the function on their own.

Source text

server-auth-actions.md · MIT
---
title: Authenticate Server Actions Like API Routes
impact: CRITICAL
impactDescription: prevents unauthorized access to server mutations
tags: server, server-actions, authentication, security, authorization
---

## Authenticate Server Actions Like API Routes

**Impact: CRITICAL (prevents unauthorized access to server mutations)**

Server Actions (functions with `"use server"`) are exposed as public endpoints, just like API routes. Always verify authentication and authorization **inside** each Server Action—do not rely solely on middleware, layout guards, or page-level checks, as Server Actions can be invoked directly.

Next.js documentation explicitly states: "Treat Server Actions with the same security considerations as public-facing API endpoints, and verify if the user is allowed to perform a mutation."

**Incorrect (no authentication check):**

```typescript
"use server"

export async function deleteUser(userId: string) {
  // Anyone can call this! No auth check
  await db.user.delete({ where: { id: userId } })
  return { success: true }
}
```

**Correct (authentication inside the action):**

```typescript
"use server"

import { verifySession } from "@/lib/auth"
import { unauthorized } from "@/lib/errors"

export async function deleteUser(userId: string) {
  // Always check auth inside the action
  const session = await verifySession()

  if (!session) {
    throw unauthorized("Must be logged in")
  }

  // Check authorization too
  if (session.user.role !== "admin" && session.user.id !== userId) {
    throw unauthorized("Cannot delete other users")
  }

  await db.user.delete({ where: { id: userId } })
  return { success: true }
}
```

**With input validation:**

```typescript
"use server"

import { verifySession } from "@/lib/auth"
import { z } from "zod"

const updateProfileSchema = z.object({
  userId: z.string().uuid(),
  name: z.string().min(1).max(100),
  email: z.string().email(),
})

export async function updateProfile(data: unknown) {
  // Validate input first
  const validated = updateProfileSchema.parse(data)

  // Then authenticate
  const session = await verifySession()
  if (!session) {
    throw new Error("Unauthorized")
  }

  // Then authorize
  if (session.user.id !== validated.userId) {
    throw new Error("Can only update own profile")
  }

  // Finally perform the mutation
  await db.user.update({
    where: { id: validated.userId },
    data: {
      name: validated.name,
      email: validated.email,
    },
  })

  return { success: true }
}
```

Reference: [https://nextjs.org/docs/app/guides/authentication](https://nextjs.org/docs/app/guides/authentication)

© zebbern · MIT · zebbern/claude-code-guide

Similar IDE rules

All IDE rules for Security →

From the same set86

The whole set →
setup-use-import-maps setup-use-import-maps — a rule that swaps the old Three.js CDN <script src> tag for an import map with ES modules and a pinned version. CX Codex +1 ★ 4,719repo stars render-delta-time render-delta-time instructs agents to use delta time in animation loops so motion remains consistent across all display refresh rates. CX Codex +1 ★ 4,719repo stars memory-dispose-geometry memory-dispose-geometry is a Claude Code rule that tells the agent to release geometry when removing scene objects. It applies to Three.js resource cleanup. CX Codex +1 ★ 4,719repo stars root-cause-debugger The root-cause-debugger subagent for Claude Code and Codex reproduces failures and finds bug root causes before code changes. It helps diagnose bugs without editing code. CX Codex ★ 4,719repo stars code-reviewer code-reviewer is a Claude Code subagent that checks completed work for bugs and regressions. It runs after implementation or when an existing diff needs review. CX Codex ★ 4,719repo stars perf-visibility-toggle perf-visibility-toggle guides the AI to toggle the visible prop on Three.js components rather than conditionally unmounting them, avoiding GPU shader recompilation. CX Codex +1 ★ 4,719repo stars perf-r3f-perf The perf-r3f-perf rule teaches Claude Code about r3f-perf, a performance monitoring library for Three.js scenes in real time. Spot frame drops, memory leaks, and unnecessary matrix recalculations as they happen. CX Codex +1 ★ 4,719repo stars codebase-mapper codebase-mapper maps repository structure, call chains, and data flows before code changes without mutating any files. CX Codex ★ 4,719repo stars

More in the catalog

Project sponsors

Companies that keep this analytics open