Cookie prefixes are special beginnings of a cookie's name, __Secure- and __Host-, that make a supporting browser reject the cookie unless it meets stricter conditions. They are a defense against cookie injection and overwriting by less trusted code or subdomains.
Why it matters
Cookies do not carry the origin that set them. A compromised or less trusted subdomain can set a cookie for the parent domain that overrides your session cookie, enabling session fixation. A __Host- cookie cannot be set that way.
Rules enforced by the browser:
__Secure-requires theSecureattribute and a secure origin.__Host-requiresSecure,Path=/, and noDomainattribute, so the cookie is bound to the exact host.
Example
Set-Cookie: __Host-session=9f2c...; Secure; HttpOnly; Path=/; SameSite=Lax
If you add Domain=example.com to that header, the browser silently discards the cookie, which can look like a login that never sticks.
Common mistakes
- Using
__Host-while still setting aDomainattribute, so the cookie disappears. - Needing the cookie across subdomains, which
__Host-deliberately prevents. - Forgetting the prefix is case-sensitive in the name check in some browsers.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.