Cookie Security Prefixes
Cookie prefixes (__Host- and __Secure-) provide additional browser-enforced security guarantees for cookies.
Results in 1–3 minutes · Free · No signup required
Want the result for your own site? Free Cookie Security Checker — paste your domain, get the report.
Why It Matters
__Host- prefix ensures cookies are set securely from the exact origin, preventing subdomain attacks. __Secure- ensures cookies are only sent over HTTPS.
How We Check
We check if session cookies use appropriate prefixes and verify the required attributes are set correctly.
Good vs Bad Values
| Value | Verdict | Why |
|---|---|---|
Set-Cookie: __Host-session=abc; Secure; Path=/; HttpOnly; SameSite=Lax | Good | The strongest form. The browser accepts it only from a secure origin, without a Domain attribute and with Path=/, so a subdomain or a plain-HTTP response cannot overwrite it. |
Set-Cookie: __Secure-session=abc; Secure; Domain=example.com; HttpOnly; SameSite=Lax | Good | For cookies that must be shared across subdomains. The browser guarantees only that it was set over HTTPS with the Secure attribute. |
Set-Cookie: __Host-csrf=abc; Secure; Path=/; SameSite=Strict | Good | CSRF tokens benefit too: a sibling subdomain can no longer plant a known token (cookie tossing). |
Non-session cookie with no prefix (for example theme=dark) | Good | The scanner only looks at names that resemble session or authentication cookies. Preferences and analytics cookies are not flagged. |
Set-Cookie: sessionid=abc; Secure; HttpOnly | Bad | Session-style name without a prefix. A hostile or compromised subdomain, or an attacker on a plain-HTTP connection, can set a cookie with the same name and fix the victim's session. |
Set-Cookie: PHPSESSID=abc; Path=/ | Bad | A well-known framework default name. Besides the missing prefix it lacks Secure and HttpOnly, which the Set-Cookie check also covers. |
Set-Cookie: __Host-session=abc; Secure; Path=/app | Bad | A __Host- cookie must have Path=/. The browser rejects it, so the session never gets set, and the scanner flags the path. |
Set-Cookie: __Host-session=abc; Path=/ | Bad | The Secure attribute is missing. Both prefixes require it, and a conforming browser drops the cookie. |
Set-Cookie: __Secure-token=abc; HttpOnly | Bad | No Secure attribute, so the browser refuses it and logins fail. |
Set-Cookie: __Host-session=abc; Secure; Path=/; Domain=example.com | Bad | A Domain attribute is forbidden with __Host-, so the browser drops the cookie. The scanner itself reports the Secure and Path rules; the Domain rule is enforced by the browser. |
How to Fix
Use __Host-session=value; Secure; Path=/ for session cookies. Use __Secure- prefix for other sensitive cookies that need subdomain access.
Plain HTTP response header — what the browser must receive:
Set-Cookie: __Host-session=<value>; Secure; Path=/; HttpOnly; SameSite=Lax
Express with express-session (set the name; Secure behind a proxy needs trust proxy):
app.set("trust proxy", 1);
app.use(session({
name: "__Host-sid",
secret: process.env.SESSION_SECRET,
cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
}));
PHP (php.ini): session.name = "__Host-PHPSESSID", session.cookie_secure = 1, session.cookie_httponly = 1, session.cookie_path = /, and no session.cookie_domain. Django: SESSION_COOKIE_NAME = "__Host-sessionid", SESSION_COOKIE_SECURE = True, and leave SESSION_COOKIE_DOMAIN unset.
Next.js with Auth.js / NextAuth: on HTTPS the library already prefixes its session token with __Secure- and its CSRF token with __Host-. For your own cookies:
cookies().set("__Host-app-session", token, {
secure: true,
httpOnly: true,
sameSite: "lax",
path: "/",
});
Nginx stop-gap for legacy applications you cannot change yet: proxy_cookie_flags ~ secure httponly; adds the attributes to every cookie passing through the proxy, but it cannot add a prefix, so rename the cookie in the application when you can.
Verify with curl -sI https://example.com | grep -i set-cookie and with DevTools → Application → Cookies, where a rejected prefixed cookie is simply missing and the Issues tab explains why.
Common Mistakes
- Renaming the cookie but keeping `Domain=.example.com`. `__Host-` forbids the Domain attribute; if you need subdomain sharing, use `__Secure-` instead.
- Missing `Path=/`. Without an explicit path the browser uses the request's directory, which makes a `__Host-` cookie invalid. Always write `Path=/`.
- Setting the cookie over plain HTTP in development. Browsers reject prefixed cookies on insecure origins (with `localhost` treated as secure in some browsers), so use a different name in dev or serve dev over HTTPS.
- Renaming without a migration. Existing users still hold the old cookie; accept both names for one session lifetime, then delete the old one with an expired `Set-Cookie`.
- Setting `Secure` behind a TLS-terminating proxy and not telling the framework. Express needs `app.set("trust proxy", 1)` or the cookie is never marked Secure and the browser rejects it.
- Mixing up the spelling. The prefixes are written `__Host-` and `__Secure-` with two leading underscores; `_Host-` or `__Hosts-` are ordinary names with no guarantees.
Frequently Asked Questions
What is Cookie Security Prefixes?
Cookie prefixes (__Host- and __Secure-) provide additional browser-enforced security guarantees for cookies.
Why does Cookie Security Prefixes matter for website security?
__Host- prefix ensures cookies are set securely from the exact origin, preventing subdomain attacks. __Secure- ensures cookies are only sent over HTTPS.
How do I fix Cookie Security Prefixes issues?
Use __Host-session=value; Secure; Path=/ for session cookies. Use __Secure- prefix for other sensitive cookies that need subdomain access.
Related Security Checks
Related Tool
Cookie Security Checker
Run all 2 related checks with our free cookie security checker
Check Your Website Now
Run a free security scan to check for Cookie Security Prefixes issues and 61 other security checks.
Scan Your Website Free