criticalLogins and sessions

Client-Side Only Auth Check

Authentication is checked only on the client side using browser storage.

Why it matters

Client-side auth checks can be trivially bypassed. An attacker can set localStorage.setItem('token', 'fake') in the browser console and gain full access. All authentication must be verified server-side.

What it looks like

This is the shape of code that triggers the rule. AI tools produce it because it works, and nothing tells them it is unsafe.

Auth check via localStorage
const token = localStorage.getItem('token');
if (!token) {
  window.location.href = '/login';
}

The smallest fix

minimal patch
// Add server-side verification:
// Client sends token in header, server verifies it
const response = await fetch('/api/protected', {
  headers: { Authorization: `Bearer ${token}` }
});
// Server: verify token before responding

Let your AI tool fix it

When the scanner finds this in your project, it fills in the file and line for you. This is the prompt it gives you to paste into Claude Code, Cursor or whatever you use.

The file [the file] at line [the line number] performs client-side auth checking using browser storage: [the flagged code]. This is insecure. Move authentication verification to the server side.

How to check the fix worked

1. Clear localStorage and verify the app redirects to login
2. Set a fake token in localStorage and verify server rejects it
3. Verify all protected API routes require server-side auth

Further reading