Cookie name prefixes (__Host- / __Secure-)

Session cookies do not use the __Host- or __Secure- name prefixes, so a subdomain, an HTTP origin or a lookalike path could plant a cookie that your site accepts as its own.

Do this: Rename session cookies to __Host- with Secure and Path=/. Without the prefix, a subdomain or an HTTP response can overwrite your session cookie.
PassSession cookies use the __Host- or __Secure- prefix correctly.
InfoSession cookies do not use a cookie name prefix, or a prefixed cookie violates its rules.

The fix, in one snippet

Example to adapt Set-Cookie
Set-Cookie: __Host-session=…; Secure; HttpOnly; SameSite=Lax; Path=/

Illustrative values. Change the paths, hostnames and options to match your own site before using it.

The sections below explain what is tested, why it matters and the alternatives.

What we test

Scan.now looks at the names of the cookies set on the response to /. It reports, as information, whether the session-like cookies use a prefix, and it validates any prefixed cookie against the rules browsers enforce: a __Secure- cookie must carry the Secure attribute and be set from an HTTPS origin; a __Host- cookie must additionally have Path=/ and no Domain attribute. A prefixed cookie that breaks its rule is flagged, because the browser rejects it silently and the application will behave as if the cookie was never set. Unprefixed session cookies are reported as an opportunity rather than a fault: prefixes are a hardening step on top of the flags checked in cookie-secure-flag, cookie-httponly-flag and cookie-samesite.

Why it matters

Cookies have a weaker isolation model than the rest of the web platform. A cookie for example.com can be set by any subdomain (blog.example.com, an abandoned old.example.com that someone has taken over) and, in browsers without the Secure-overwrite protection, by a plain-HTTP response for the same host. When the server reads session=..., it cannot tell where that cookie came from. That enables session fixation: the attacker plants a session identifier they already know, waits for the victim to log in under it, and then uses it. It also enables cookie tossing, where a subdomain sets a cookie with a more specific path that shadows the real one. The __Host- prefix closes both: a browser will only accept a __Host- cookie if it was set over HTTPS by the exact host, with Path=/ and no Domain, so the server knows those conditions held. The cookie flags guide explains the prefixes alongside the attributes.

How to fix it

Rename the session cookie and satisfy the prefix rules:

Set-Cookie: __Host-session=abc123; Path=/; Secure; HttpOnly; SameSite=Lax

Express with express-session:

app.use(session({
  name: '__Host-sid',
  cookie: { path: '/', secure: true, httpOnly: true, sameSite: 'lax' },  // no domain
}));

Django (settings.py):

SESSION_COOKIE_NAME = '__Host-sessionid'
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_DOMAIN = None
SESSION_COOKIE_PATH = '/'
CSRF_COOKIE_NAME = '__Host-csrftoken'
CSRF_COOKIE_SECURE = True

PHP: session.name = __Host-PHPSESSID with session.cookie_secure = 1, session.cookie_path = / and an empty session.cookie_domain. Use __Secure- instead when the cookie must be shared across subdomains (it still requires Secure). Renaming a session cookie logs everyone out once, so deploy it at a quiet time and make sure any code or proxy rule that references the old name is updated.

Where this fits

Cookie name prefixes (__Host- / __Secure-) is check 4 of 4 that the website vulnerability scanner runs under cookie security, ordered the way they are worth fixing. That ordering is the point: Fixing this one while the check above it still fails buys less than it looks like.

Fix this one first

Above it in the same category sits Cookie without SameSite attribute (low), where a cookie is set without a SameSite attribute, or with SameSite=None but no Secure flag. An attacker who has that does not need this, so it is the better use of the same hour.

Found in the same scan

The website vulnerability scanner reports this alongside checks from other categories that are at least as serious, including Certificate chain and hostname validation, where the certificate presented for this hostname did not validate: The chain does not reach a trusted root, an intermediate is missing, the name does not match, or the certificate is self-signed or expired, and Exposed .env configuration file, where a .env configuration file is served from the web root. A single run of website vulnerability scanner answers all of them at once.

Prompt for an AI Hand this check to an assistant Sign in to copy it
The first few lines
You are a senior web engineer. I ran a security and SEO scanner against my site and it reported the finding below. Fix it properly rather than suppressing the symptom.

Finding: Cookie name prefixes (__Host- / __Secure-) (info severity)
Scanner check id: cookie-prefixes
17 more lines, including the evidence and the exact fix

The rest of this prompt names the pages and line numbers we found the problem on, the configuration to change, and the constraints a good answer has to respect. It is free, it just needs an account so the work is not scraped wholesale.

Sign in with Google

Signing in is free and takes one click. We store your email address and nothing else.

References

  1. MDN: Set-Cookie, cookie prefixes
  2. IETF: Cookies: HTTP State Management Mechanism (rfc6265bis)
  3. OWASP Session Management Cheat Sheet

Related guides