Client-Side Auth Only
Password comparisons, or auth tokens kept in localStorage, in client components
criticalSecurity
client-side-auth-onlySeverity depends on context. Critical for a password comparison. Warning for an auth token read from or written to localStorage or sessionStorage.
Why this matters
Any auth logic in client code can be bypassed by opening DevTools. Password comparisons, role checks, and token validation must happen on the server where users can't tamper with them.
Example
components/admin-panel.tsx"use client";
export function AdminPanel({ password }: { password: string }) {
if (password !== "admin123") {
return <p>Access denied</p>;
}
return <div>Admin content here</div>;
}components/admin-panel.tsx// Server component or API route
import { auth } from "@/lib/auth";
export default async function AdminPanel() {
const session = await auth();
if (session?.user?.role !== "admin") {
redirect("/");
}
return <div>Admin content here</div>;
}How to fix
Move all auth logic to server components, API routes, or middleware. Client code should only render based on the session state provided by the server.
Reference
- In the output
- Findings carry
"ruleId": "client-side-auth-only"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line client-side-auth-only- Silence a whole file
// prodlint-disable client-side-auth-onlyat the top of the file- How it works
- Matches text patterns. Source on GitHub