Opens in a new tab

Cookie flags: Secure, HttpOnly and SameSite on every cookie

Three attributes on Set-Cookie decide how safe a cookie is: Secure keeps it off plain HTTP, HttpOnly keeps it away from scripts, and SameSite keeps it out of requests other sites trigger. A session cookie should carry all three — and should not rely on browser defaults, which differ.

Defined inRFC 6265, and the RFC 6265bis revision in final review
SameSite missingChrome and Edge treat it as Lax; Firefox and Safari do not
SameSite=NoneNeeds Secure, or the cookie is ignored
Strongest formThe __Host- prefix

Check cookie flags on your site

Enter a domain: we fetch its homepage and read every security header, this one first.

What it does

Secure sends the cookie only over HTTPS, so it cannot be read off a plain HTTP connection. HttpOnly hides it from document.cookie, so a script injected into the page cannot steal it — the browser still sends it with requests. SameSite decides whether it goes with requests started by other sites: Strict never, Lax only on top-level navigation such as following a link, None always.

Chrome and Edge treat a cookie without SameSite as Lax, but Firefox and Safari send it with every cross-site request — so a cookie that relies on the default is protected in some browsers and not others. Set it explicitly.

Directives and values

Directive or valueWhat it does
SecureSent over HTTPS only. Protects confidentiality, not integrity.
HttpOnlyNot readable by JavaScript; still sent with fetch() and XHR requests.
SameSite=StrictOnly on requests from your own site.
SameSite=LaxAlso on top-level navigation from other sites using a safe method such as GET.
SameSite=NoneOn every request — must be paired with Secure.
__Host- prefixThe cookie must be Secure, have Path=/ and no Domain, which locks it to one host.

What a session cookie should look like

Set-Cookie: __Host-SessionID=<value>; Secure; HttpOnly; SameSite=Strict; Path=/

That is OWASP’s example. SameSite=Lax is the practical choice when people arrive logged in from links on other sites; SameSite is a second layer against cross-site request forgery, not a replacement for CSRF tokens.

How to set them

Cookie flags are set by whatever creates the cookie — usually the application or its framework, which has an option for each flag. In PHP:

PHP

setcookie( 'name', $value, [
	'secure'   => true,
	'httponly' => true,
	'samesite' => 'Lax',
	'path'     => '/',
] );

Common mistakes

  • SameSite=None without Secure — the browser ignores the cookie.
  • Relying on the Lax default, which Firefox and Safari do not apply.
  • A __Host- cookie with a Domain attribute or without Path=/ — it is rejected.
  • Assuming Secure protects a cookie from being overwritten: it keeps it private, not tamper-proof.

What we recommend

Give every cookie Secure and an explicit SameSite, and every session or login cookie HttpOnly too, ideally with the __Host- prefix. Our check reads the cookies the homepage sets; log-in pages and carts often set more — check those in the browser’s developer tools.

Questions

Why does my scanner flag cookies I did not set?

Plugins, analytics and chat widgets set their own. Our check lists each cookie by name with the flags it lacks, so you can see which part of the site sets it.

Sources

Checked on 25 September 2026 against these official sources:

Know when a header disappears

Add your domain and we scan it on a schedule — security headers, certificate, HTTPS, DNS and email — and email you when a security header is removed, a certificate changes or HTTPS stops redirecting. Free for your first domain.

Create a free account