Missing Auth Checks
API routes with no authentication check (middleware-aware)
criticalSecurity
auth-checksSeverity depends on context. Critical on routes that handle POST, PUT, PATCH or DELETE. Info on read-only routes, and on any route when auth middleware is detected.
Why this matters
An unprotected API route is an open door. Anyone with the URL can create, change or delete data. AI tools often scaffold routes without auth because the prompt didn't mention it.
Example
app/api/users/route.tsexport async function POST(req: Request) {
const body = await req.json();
const user = await db.user.create({ data: body });
return Response.json(user);
}app/api/users/route.tsexport async function POST(req: Request) {
const session = await getServerSession();
if (!session) {
return new Response("Unauthorized", { status: 401 });
}
const body = await req.json();
const user = await db.user.create({ data: body });
return Response.json(user);
}How to fix
Check the session at the top of every handler that reads or changes data, or cover the route with auth middleware (Clerk, NextAuth, Supabase). Routes whose path says they are public by design (auth, login, signup, callback, webhook, health, cron, public) are skipped.
Reference
- In the output
- Findings carry
"ruleId": "auth-checks"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line auth-checks- Silence a whole file
// prodlint-disable auth-checksat 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