Medium severity

How to fix cookies without a SameSite attribute

Your cookie is missing the `SameSite` attribute. SameSite determines whether the browser sends the cookie on cross-site requests. Without it, the cookie is sent on every request — which opens CSRF attacks on older browsers. Modern browsers default to `Lax`, but you should not rely on that. Set `SameSite=Lax` for most cookies, `SameSite=Strict` for sensitive operations (banking, admin), `SameSite=None; Secure` only when you truly need cross-site access.

Why it matters

SameSite is the simplest CSRF defense. Lax is good for most apps. Strict is safest but breaks external links. None is only for explicit cross-site auth (embedded widgets) and requires Secure.

How to check

  1. 01DevTools → Application → Cookies: check SameSite column.
  2. 02`Lax` is the default and usually fine. `None` without `Secure` is invalid.

Or let SafeToShip check it for you in 60 seconds:

How to fix it

Next.js

Set sameSite on every cookie. Lax is the default for most cases.

cookies().set({
  name: 'session',
  value: token,
  secure: true,
  httpOnly: true,
  sameSite: 'lax',  // or 'strict' for admin/finance
});

Generic

Add `SameSite=Lax` to every cookie.

Set-Cookie: session=abc; Secure; HttpOnly; SameSite=Lax

AI prompt

Copy-paste into your AI tool

Paste this prompt into Cursor, Lovable, Bolt, v0, or Claude Code and it will walk through the fix for your specific codebase.

Audit every cookie my app sets. Add SameSite=Lax as the default. For cookies on admin or billing routes, use SameSite=Strict. If I have any cookies that need to work in embedded iframes or cross-site contexts, use SameSite=None; Secure and tell me exactly why that cookie needs cross-site access.

FAQ

Frequently asked questions

Does SameSite replace CSRF tokens?
It replaces most of the need. For extra-sensitive operations (money transfers, privilege changes), keep CSRF tokens as defense in depth.
I'm embedding my app in an iframe — what do I do?
Use `SameSite=None; Secure`. Without Secure, None is rejected by browsers.

Scan your site for this and 50+ other issues

Free scan. Results in 60 seconds. No account required.