Insecure Cookie
Session cookies set without httpOnly, secure or sameSite
warningSecurity
insecure-cookieWhy this matters
Cookies without httpOnly can be stolen via XSS. Without secure, they're sent over plain HTTP. Without sameSite, they're vulnerable to CSRF. AI tools rarely set all three.
Example
app/api/login/route.tsexport async function POST(req: Request) {
const token = await signIn(await req.json());
const response = NextResponse.json({ ok: true });
response.cookies.set("session", token);
return response;
}app/api/login/route.tsexport async function POST(req: Request) {
const token = await signIn(await req.json());
const response = NextResponse.json({ ok: true });
response.cookies.set("session", token, {
httpOnly: true,
secure: true,
sameSite: "lax",
});
return response;
}How to fix
Set httpOnly, secure and sameSite on every cookie that holds a session, token or JWT.
Reference
- In the output
- Findings carry
"ruleId": "insecure-cookie"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line insecure-cookie- Silence a whole file
// prodlint-disable insecure-cookieat the top of the file- How it works
- Matches text patterns. Source on GitHub