Insecure Cookie

Session cookies set without httpOnly, secure or sameSite

warningSecurityinsecure-cookie

Why 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

Flaggedapp/api/login/route.ts
export 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;
}
Fixedapp/api/login/route.ts
export 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 --json and 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-cookie at the top of the file
How it works
Matches text patterns. Source on GitHub