Skip to content
Tutorials

Cookie Attributes Explained: SameSite, Secure, HttpOnly, Prefixes and Partitioned

AIDToolStack EditorialNovember 7, 20268 min read
CookiesWeb SecuritySameSiteCHIPSPrivacy
Share:Twitter

Login works on localhost. In production the session cookie vanishes as soon as the app loads inside a partner's iframe, or a security scanner flags "cookie without HttpOnly", or Safari users get logged out and Chrome users don't. All three come down to the half-dozen attributes on one Set-Cookie line, and to the fact that browsers don't all treat a missing attribute the same way.

Here's what each attribute does according to the specs and MDN, what browsers default to as of November 2026, and where third-party cookies stand now that Google has changed its plans.

Which spec, by the way

The RFC is still RFC 6265, from April 2011. Its replacement, draft-ietf-httpbis-rfc6265bis, is at revision -22 (1 December 2025), has been submitted to the IESG and sits in the RFC Editor queue, but as of November 2026 it hasn't been published as an RFC. Browsers already implement most of it (SameSite and the cookie prefixes come from the bis work), so it's the more useful document to read.

One attribute, one job

Set-Cookie: __Host-sid=9f2c1e7a; Path=/; Max-Age=3600; Secure; HttpOnly; SameSite=Lax
AttributeWhat it controlsIf you leave it out
DomainWhich hosts get the cookie. Setting it includes all subdomainsHost-only: sent back only to the exact host that set it
PathWhich URL paths get it (/docs matches /docs/Web, not /docsets)The path of the request URL that set it
Expires / Max-AgeWhen it dies. Max-Age wins if both are set; zero or negative deletesSession cookie
SecureOnly sent over https: (localhost excepted)Sent over plain HTTP too
HttpOnlyHidden from document.cookieReadable and writable by any script on the page
SameSiteWhether it rides on cross-site requestsDepends on the browser (see below)
PartitionedStored per top-level site (CHIPS)Unpartitioned

All of that is from MDN's Set-Cookie reference. Two Domain details trip people up. Setting Domain=example.com widens the cookie to every subdomain, so the most restrictive choice is to omit it. And leading dots are ignored now, so .example.com and example.com mean the same thing.

Secure and HttpOnly

Secure means the cookie only goes over HTTPS. MDN adds that plain http: pages can't set Secure cookies at all, and that localhost is exempt, which is why things work on your machine over HTTP and you never notice a missing Secure until something else breaks.

HttpOnly stops JavaScript from reading the cookie through document.cookie. The bis draft also says script APIs can neither create nor overwrite a cookie that's flagged HttpOnly. What it doesn't do is stop the cookie being sent. MDN is explicit that an HttpOnly cookie "will still be sent with JavaScript-initiated requests". So HttpOnly stops an XSS bug from stealing your session token, but the injected script can still make authenticated requests while the page is open. It's worth having on every session cookie; it isn't an XSS fix. (If you're weighing cookies against tokens in localStorage, our JWT mistakes post covers that trade.)

SameSite, and what "site" means

SameSite is about sites, not origins. A site is scheme plus registrable domain (eTLD+1), so https://app.example.com and https://api.example.com are same-site even though they're different origins (web.dev). The scheme counts: http://example.com and https://example.com are cross-site. And entries on the Public Suffix List change the boundary: alice.github.io and bob.github.io are different sites.

Matrix of when a cookie is sent for SameSite Strict, Lax and None: same-site requests always; cross-site top-level GET navigation with Lax and None; cross-site form POST and subresources only with None, and None cross-site is still subject to third-party cookie rules
Matrix of when a cookie is sent for SameSite Strict, Lax and None: same-site requests always; cross-site top-level GET navigation with Lax and None; cross-site form POST and subresources only with None, and None cross-site is still subject to third-party cookie rules
  • Strict: only same-site requests. A user who clicks a link to your app from their email arrives without the cookie on that first request, so they look logged out until the next navigation.
  • Lax: same-site requests, plus cross-site top-level navigations with a safe method. Links work; cross-site form POSTs, iframes and fetch() don't carry it.
  • None: always sent, but only together with Secure: MDN says it "must also be set" when using this value.

The default is where browsers split. Chrome started treating cookies with no SameSite attribute as Lax in Chrome 80, with enforcement reaching 100% of stable Chrome in August 2020 (Chromium). It also allows those defaulted cookies on top-level cross-site POSTs if they're at most two minutes old, which Chromium calls a temporary intervention. The OWASP CSRF cheat sheet notes that Firefox and Safari do not default to Lax. The fix is boring: always set SameSite explicitly.

For a normal first-party web app, I'd use Lax on the session cookie. Strict is fine for cookies that only guard dangerous actions, but the logged-out-on-arrival effect annoys people. None is for cookies that genuinely need to work inside someone else's page.

Don't treat SameSite as your CSRF defence. OWASP calls it "useful as a defense-in-depth control" that "does not replace a proper CSRF defense in most deployments", for two concrete reasons: any sibling subdomain is same-site (a takeover of old-promo.example.com can send requests your cookies accompany), and Lax still sends cookies on top-level GETs, so a state-changing GET endpoint is exposed. Keep the CSRF token. Our web security checklist has the rest.

Prefixes: rules the browser enforces for you

Cookie name prefixes make the browser reject a cookie that doesn't meet certain rules (MDN):

  • __Secure-: must be set with Secure from an HTTPS page.
  • __Host-: also must have no Domain and Path=/. That pins it to one host, so a compromised subdomain can't overwrite it. OWASP recommends it for the same reason.
  • __Http- and __Host-Http-: newer; they additionally require HttpOnly, proving the cookie came from a Set-Cookie header rather than script.

MDN's caveat applies: browsers that don't support prefixes just accept the cookie, so the prefix adds a guarantee where it's supported and costs nothing where it isn't. __Host- is my default for session cookies. Check MDN's compatibility table before depending on the two Http prefixes.

Lifetime and size limits

Max-Age takes seconds and beats Expires when both are present. The bis draft says user agents shouldn't keep a cookie more than 400 days (34,560,000 seconds) in the future and should cut longer values down to the limit, so "expires in 10 years" doesn't mean what it used to.

On size, RFC 6265 asks browsers to support at least 4096 bytes per cookie, 50 cookies per domain and 3000 in total. The bis draft is stricter about the failure: if name plus value exceed 4096 octets the whole cookie should be ignored, and an attribute value over 1024 octets is ignored. A session ID doesn't come close; a JWT stuffed with claims can.

Third-party cookies in November 2026

If you read in 2023 that Chrome was killing third-party cookies, that's no longer the plan. In April 2025 Google said it "will not be rolling out a new standalone prompt for third-party cookies" and would keep its existing settings (Privacy Sandbox blog). In October 2025 it said Chrome "will maintain our current approach to offering users third-party cookie choice" and retired most Privacy Sandbox APIs, including Topics, Protected Audience, Attribution Reporting, IP Protection and Related Website Sets. CHIPS and FedCM stay, having "seen broad adoption, including support from other browsers" (update).

Where that leaves the defaults, per MDN's third-party cookies guide:

BrowserThird-party cookies by default
ChromeAllowed; blocked in Incognito or if the user turns them off
FirefoxTotal Cookie Protection: a separate jar per site, on by default
SafariTracking prevention restricts them by default
EdgeBlocks trackers from unvisited sites and known harmful trackers

So "works in Chrome" proves very little for an embedded widget.

Partitioned cookies (CHIPS)

If your third-party cookie only needs to work per embedding site (a chat widget's session, an embedded map's preferences), add Partitioned. The cookie gets "double-keyed: by the origin that sets them and the origin of the top-level page" (MDN):

Set-Cookie: __Host-chat=a1b2; SameSite=None; Secure; Path=/; Partitioned
The same third-party chat widget embedded on two different top-level sites gets a separate partitioned cookie jar under each, keyed by the top-level site, so it can't link the user across them
The same third-party chat widget embedded on two different top-level sites gets a separate partitioned cookie jar under each, keyed by the top-level site, so it can't link the user across them

Partitioned requires Secure. MDN lists CHIPS as Baseline 2025, working across current browsers since December 2025. If you need the same cookie across a few related sites, partitioning won't help; the Storage Access API, which asks the user per frame, is the documented route.

Setting them in code

Express's res.cookie maps options to attributes. Note that its maxAge is in milliseconds even though the header's Max-Age is in seconds:

res.cookie("__Host-sid", sessionId, {
  httpOnly: true,
  secure: true,
  sameSite: "lax",
  path: "/",
  maxAge: 60 * 60 * 1000, // one hour, in ms
});

// a widget cookie that must work inside other sites
res.cookie("__Host-chat", chatId, {
  secure: true,
  sameSite: "none",
  partitioned: true,
  path: "/",
});

To check what a server actually sends, grab the header with curl -sS -i https://yourapp.example/login and paste the Set-Cookie value into our cookie parser. It splits out each attribute and warns about a missing HttpOnly, Secure or SameSite, SameSite=None without Secure, Partitioned without Secure, broken __Secure- and __Host- prefix rules, and cookies over 4096 bytes. For the response headers that sit alongside cookies (HSTS, CSP), see our security headers guide.

  1. __Host- prefix, Path=/, no Domain.
  2. Secure and HttpOnly, always.
  3. SameSite=Lax written out, not left to the browser.
  4. A Max-Age under 400 days, and a server-side session expiry that matches.
  5. A CSRF token anyway.
  6. Embedded in other sites? SameSite=None; Secure; Partitioned, and test in Safari and Firefox before Chrome.
AE

Written by AIDToolStack Editorial

Researched from official documentation, specifications and vendor pages, listed under Sources below. Last checked November 2026.

Sources

  1. www.rfc-editor.org/rfc/rfc6265.html
  2. datatracker.ietf.org/doc/draft-ietf-httpbis-rfc6265bis/
  3. www.ietf.org/archive/id/draft-ietf-httpbis-rfc6265bis-22.html
  4. developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie
  5. developer.mozilla.org/en-US/docs/Web/Privacy/Guides/Third-party_cookies
  6. developer.mozilla.org/en-US/docs/Web/Privacy/Guides/Privacy_sandbox/Partitioned_cookies
  7. web.dev/articles/same-site-same-origin
  8. www.chromium.org/updates/same-site/
  9. cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html
  10. privacysandbox.google.com/blog/privacy-sandbox-next-steps
  11. privacysandbox.google.com/blog/update-on-plans-for-privacy-sandbox-technologies
  12. privacysandbox.google.com/cookies
  13. expressjs.com/en/5x/api/response/

Related Posts

Explore on AIDToolStack

Discover tools and servers featured in our directory.

MCP Servers

Trigger.dev Jobs MCP ServerManage Trigger.dev background jobs from your AI coding assistant. Monitor job runs, trigger tasks manually, inspect execution logs, manage schedules, and debug failed runs. The server provides operational visibility into your background job infrastructure — see which tasks are running, queued, or failed, and take action. Your AI can help diagnose job failures from execution logs, retry failed tasks, and optimize concurrency configurations for better throughput.Tailscale Network MCP ServerManage your Tailscale mesh VPN network from your AI coding assistant. View connected devices, manage ACLs, configure exit nodes, check device status, and manage DNS settings. The server provides visibility into your Tailscale network — see which machines are online, troubleshoot connectivity issues, manage network access policies, and configure routes. Useful for developers managing distributed infrastructure where Tailscale provides secure networking between services.Portainer Docker MCP ServerManage Docker environments through Portainer's API from your AI coding assistant. Control containers, images, networks, and volumes across multiple Docker hosts and Kubernetes clusters. The server provides tools for container lifecycle management, image pulling and building, stack deployment, and resource monitoring. Portainer's multi-environment management makes this server particularly valuable for teams managing containers across development, staging, and production environments.

Reviews

Sign in to leave a review.

No reviews yet. Be the first!

Comments

Sign in to leave a comment.

No comments yet. Be the first!

Sponsor Our Newsletter

Reach thousands of developers who are actively evaluating AI tools, MCP servers, and dev infrastructure. Our weekly newsletter goes to engaged technical decision-makers.

Growing subscriber baseHigh open rates

All sponsored content is clearly labeled per our editorial policy.