Free check
Cookie security check: Secure, HttpOnly and SameSite
Session cookies are the keys to your users' accounts. Three small flags decide whether they can be stolen over Wi-Fi, read by an injected script, or sent along with a forged request from another site.
Why it matters
Without Secure, a cookie can be sent over plain HTTP and intercepted. Without HttpOnly, any script running on the page can read it, which turns a small cross-site scripting bug into account takeover. Without SameSite, other sites can make requests that carry your users' cookies.
What this check looks at
- Every cookie set on up to five pages
- Secure (on HTTPS sites), HttpOnly on cookies that look like sessions or auth tokens, and SameSite
How to fix it
Express
res.cookie("session", value, {
secure: true,
httpOnly: true,
sameSite: "lax",
});
PHP (php.ini)
session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = "Lax"
Django (settings.py)
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = "Lax"
CSRF_COOKIE_SECURE = True
Next.js (route handler)
import { cookies } from "next/headers";
(await cookies()).set("session", value, {
secure: true,
httpOnly: true,
sameSite: "lax",
});
Questions
Should SameSite be Lax or Strict?
Lax is the right default for most sites: it blocks cookies on cross-site form posts but keeps users logged in when they follow a link to you. Use Strict for especially sensitive actions.
Can JavaScript-set cookies be HttpOnly?
No. HttpOnly cookies can only be set by the server, which is exactly why they're safer for sessions.