Lesson 2 of 14 · 15m
Cookie Flags That Actually Matter
HttpOnly, Secure, SameSite, Domain, and __Host- each answer a different question the browser asks before attaching a cookie.
What the flags actually do
Set-Cookie: __Host-sess=abc; Secure; HttpOnly; SameSite=Lax; Path=/ is six small decisions, and each one answers a different question the browser asks when deciding whether to attach the cookie to a request.
HttpOnly— removed fromdocument.cookieand the cookie APIs. XSS can't read it. Note the precision: XSS can still ride it — an injected script can't exfiltrate the value, but it can firefetch('/api/transfer')from the victim's page and the cookie attaches automatically. HttpOnly stops theft, not use.Secure— only sent over HTTPS. Without it the cookie goes out in plaintext on any HTTP request to the domain, and one captive-portal redirect or sslstrip session later it's gone. On production there's no defensible reason to omit it.SameSite— the CSRF lever.Strict: only same-site requests carry it.Lax: same-site plus top-level GET navigations carry it; cross-site POSTs don't.None: everything carries it — and Chrome requiresSecurealongside it. Since Chrome 80 (February 2020) a cookie with noSameSiteattribute is treated asLax, with a quirk called Lax+POST: cookies set without an explicitSameSitewithin the last two minutes still ride top-level cross-site POSTs, to keep legacy SSO flows from breaking. Firefox and Safari followed with their own defaults. SameSite killed most ambient-authority CSRF — but "most" is doing work in that sentence, and the CSRF lesson covers the rest.Path— a coarse routing hint. The RFC 6265 path-match rule sends aPath=/appcookie to/appand/app/admin, but not to/apple— the character after the prefix must be/. Still a prefix rule, not a security boundary: anything under/appsees it.Domain— the dangerous one, covered below.__Host-/__Secure-prefixes (RFC 6265bis) — the browser enforces the contract:__Host-requiresSecure,Path=/, and noDomain. Any deviation and the cookie is rejected. It's a lint rule baked into the parser.Partitioned(CHIPS) — the post-third-party-cookie mechanism: aPartitionedcookie on an embedded third-party context is keyed by the top-level site, so the tracker-in-an-iframe can't correlate visits across sites. Only relevant if you build embeddable widgets; for a first-party session cookie it solves a problem you don't have.
The wrong mental model
"Cookies are scoped to my site." They are not — they're scoped to a domain suffix the server can widen, and they ignore two boundaries people assume exist: ports and subdomains.
Cookies don't see ports. A cookie set by a service on evil.example.com:8080 is readable and overridable for example.com:443. Cookies also flow downward by default when Domain is set: Domain=example.com means every subdomain — including the stale staging.example.com A-record pointing at an IP you don't control anymore — can read the session cookie, and can also set cookies the parent sees. That second direction is cookie tossing: a hostile subdomain (or any compromised sibling) injects a cookie with a name the app trusts, and the browser happily sends both; server-side ordering quirks mean the attacker's often wins. Subdomain takeovers have repeatedly escalated into full account takeover through exactly this path.
What to actually do
Session cookie recipe: __Host-sess=<random>; Secure; HttpOnly; SameSite=Lax; Path=/ — omit Domain entirely so it stays host-only. Only reach for SameSite=None when a third-party context genuinely needs the cookie, and know that None deletes your CSRF margin so you owe the endpoint another check. Audit for stray Domain= attributes and for cookies set by sibling subdomains — Set-Cookie responses are enumerable in DevTools' Network panel, and sloppy Domain=.corp.com cookies show up constantly in real estates. When you find one, narrowing it to host-only is a one-attribute fix with a real payoff.
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
Zero-Trust Access for Homelabbers: Teleport vs. Tailscale vs. WireGuard vs. Cloudflare Tunnel
Four tools solve four different problems that all get pitched as the same problem. Here's what each one does, where each one breaks, and the combination that covers a real homelab without paying an SSO tax you didn't see coming.
The SSO Tax: Why Self-Hosted Projects Are Gating Login Behind a Paywall
A growing list of open-core self-hosted projects, from Grafana to Planka, gate single sign-on behind an Enterprise tier. Here's which protocol actually gets paywalled, and what to check before you deploy.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.