Skip to content

/flags/http/set-cookie-samesite

Set-Cookie attributes: SameSite, Secure, HttpOnly, Max-Age

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · curl 8.21.0 (x86_64-w64-mingw32) libcurl/8.21.0 Schannel zlib/1.3.2updated 2026-10-20
tool
HTTP
command
Set-Cookie header
flag
SameSite, Secure, HttpOnly, Max-Age, Path, Domain
default
treated as SameSite=Lax by Chromium-based browsers when the attribute is missing

Attributes on a Set-Cookie header control when the browser sends the cookie back. SameSite decides whether it goes with cross-site requests, Secure limits it to HTTPS, HttpOnly hides it from document.cookie, and Max-Age or Expires set how long it lives. A session cookie for a normal web app should be Secure; HttpOnly; SameSite=Lax.

See the header a server sends

bash
node -e '
const http = require("http");
const server = http.createServer((req, res) => {
  res.setHeader("Set-Cookie", [
    "session=abc123; Path=/; Max-Age=3600; HttpOnly; Secure; SameSite=Lax",
    "prefs=dark; Path=/; Max-Age=31536000; SameSite=Strict",
  ]);
  res.end("ok");
}).listen(0, () => {
  http.get({ port: server.address().port }, (res) => {
    for (const c of res.headers["set-cookie"]) console.log("Set-Cookie:", c);
    server.close();
  });
});'

Output

Set-Cookie: session=abc123; Path=/; Max-Age=3600; HttpOnly; Secure; SameSite=Lax
Set-Cookie: prefs=dark; Path=/; Max-Age=31536000; SameSite=Strict

Attributes

AttributeEffect
SameSite=Strictsent only for same-site requests, not even when following a link from another site
SameSite=Laxsent for same-site requests and top-level navigations (link clicks), not for cross-site subrequests
SameSite=Nonesent with every request; requires Secure
Securesent only over HTTPS (and to localhost)
HttpOnlynot readable from JavaScript (document.cookie)
Max-Age=Nexpires after N seconds; takes precedence over Expires
Path=/sent for URLs under this path
Domain=example.comalso sent to subdomains; omit it to restrict to the exact host

Common problems

  • A cookie with SameSite=None but without Secure is rejected by current browsers.
  • Cross-site iframes and APIs on another site need SameSite=None; Secure, and third-party cookie restrictions may still block them.
  • __Host- prefixed names (for example __Host-session) require Secure, Path=/ and no Domain, which prevents subdomains from overwriting them.

Sources