~/blog / cookie-security-flags

Cookie security flags explained: Secure, HttpOnly, SameSite

// published 2026-04-17

Three small attributes — Secure, HttpOnly, SameSite — decide whether a cookie is a session token a careful engineer would deploy or a credential leak waiting to happen. Here's what each one does, when to use it, and what attacks it stops.

The default cookie is dangerous

By default, when a browser receives Set-Cookie: session=abc with no flags, it stores the cookie and:

Each of those is exploitable. The flags fix them one at a time.

Secure

Set-Cookie: session=abc; Secure

Browser only sends the cookie over HTTPS. Even if a network attacker can intercept HTTP requests to your domain, the cookie won't be transmitted in cleartext.

When to set: always, on every cookie. There is no scenario in 2026 where you want a cookie sent over HTTP.

What it stops: network-level credential theft on hostile WiFi, transparent proxies, MITM attackers.

HttpOnly

Set-Cookie: session=abc; Secure; HttpOnly

JavaScript can't read or modify the cookie via document.cookie. Only the browser (sending it on HTTP requests) and the server (receiving it) ever see the value.

When to set: always for session cookies, auth tokens, CSRF tokens. Skip only for cookies that legitimate JavaScript needs to read (rare — usually you should re-architect to avoid that).

What it stops: XSS-based session theft. An attacker who manages to inject JS into your page can do many bad things, but stealing the session cookie via document.cookie isn't one of them.

SameSite

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

Controls when the cookie is sent on cross-site requests. Three values:

When to use what:

What it stops: CSRF attacks. Without SameSite, an attacker's site can trick a logged-in user's browser into making an authenticated request to your site (transferring funds, changing email, etc.) and the browser will dutifully include the session cookie.

The minimum viable session cookie in 2026

Set-Cookie: session=...; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=86400

Plus rotation on login (Max-Age resets) and a server-side invalidation list for logout (cookie deletion alone isn't enough — server must also reject the value).

Common mistakes

Run the Cookie Audit on your own pages to see which flags are missing.


check_your_own_domain
Run the free Cookie Audit to diagnose this on any domain.
[ Open Cookie Audit ]
// related_reading