Knowledge Base

Set-Cookie and Cookie Attributes

Set-Cookie asks the browser to store a cookie. Inspect each cookie separately: its purpose determines which boundaries make sense.

A session-cookie example

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

The value above is a placeholder, not a session token. In supporting browsers, the __Host- prefix requires Secure, Path=/, and no Domain. That helps keep the cookie tied to its setting host.

Transport and script access

Secure limits cookie transmission to HTTPS, with browser exceptions for local development. It does not encrypt the cookie at rest. HttpOnly prevents ordinary JavaScript access, but the browser can still send the cookie on script-initiated requests.

Authentication cookies generally benefit from both attributes. A cookie intentionally read by JavaScript has different requirements. HttpOnly does not make an application immune to XSS.

SameSite values

  • Strict: send only in same-site contexts; some incoming navigation flows can lose the session.
  • Lax: also permits qualifying cross-site top-level navigation using safe methods, commonly link-following.
  • None: permits cross-site use and requires Secure.

Same-site and same-origin are different concepts. HTTPS subdomains can be same-site while being different origins. Missing SameSite can trigger browser-specific defaults; choose an explicit value after testing login and embedded flows. Third-party cookie rules still apply to None.

Scope and lifetime

Omitting Domain creates a host-only cookie. Setting it can include subdomains. Path limits which request paths receive a cookie but is not a reliable security isolation boundary.

Max-Age is seconds; Expires is a date. Max-Age takes precedence when both are present. A cookie without either is a session cookie, though browser session restoration may preserve it.

Return a separate Set-Cookie header for each cookie; do not fold them into a comma-separated value. A single public response may not reveal cookies created later during login. See cookie configuration guidance.

Sources

Copyright ©2026 MILAN INNOVATIONS LLC. All rights reserved.