Protect cookies with Secure, HttpOnly and SameSite
Updated 1 Dec 2026
What it means
One or more cookies are set without the Secure, HttpOnly or SameSite attributes. Session cookies without them can be sent over plain HTTP, read by injected JavaScript, or attached to requests from other sites (CSRF).
Why it matters
Session hijacking: an attacker who obtains a session cookie is logged in as your customer or administrator.
How to fix it
- Mark every cookie Secure (only sent over HTTPS).
- Mark session/authentication cookies HttpOnly (not readable by JavaScript).
- Set SameSite=Lax (or Strict for admin panels); use SameSite=None; Secure only for cookies that must work cross-site.
Configuration examples
nginx (nginx >= 1.19.3)
proxy_cookie_flags ~ secure httponly samesite=lax;
Apache
Header always edit Set-Cookie ^(.*)$ "$1; Secure; HttpOnly; SameSite=Lax"
IIS (web.config)
<system.web>
<httpCookies requireSSL="true" httpOnlyCookies="true" sameSite="Lax" />
</system.web>
Node.js / Express
app.use(session({ cookie: { secure: true, httpOnly: true, sameSite: 'lax' }, /* ... */ }));
app.set('trust proxy', 1); // behind a TLS-terminating proxy
Django (settings.py)
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'
CSRF_COOKIE_SECURE = True
Laravel / PHP (config/session.php)
'secure' => env('SESSION_SECURE_COOKIE', true),
'http_only' => true,
'same_site' => 'lax',
Any platform
Set-Cookie: session=...; Path=/; Secure; HttpOnly; SameSite=Lax
Check your fix
curl -sI https://YOUR_DOMAIN | grep -i set-cookieBrowser DevTools -> Application -> Cookies: check the Secure/HttpOnly/SameSite columns.
References
- https://owasp.org/www-community/controls/SecureCookieAttribute
- https://developer.mozilla.org/docs/Web/HTTP/Cookies