/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
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
| Attribute | Effect |
|---|---|
| SameSite=Strict | sent only for same-site requests, not even when following a link from another site |
| SameSite=Lax | sent for same-site requests and top-level navigations (link clicks), not for cross-site subrequests |
| SameSite=None | sent with every request; requires Secure |
| Secure | sent only over HTTPS (and to localhost) |
| HttpOnly | not readable from JavaScript (document.cookie) |
| Max-Age=N | expires after N seconds; takes precedence over Expires |
| Path=/ | sent for URLs under this path |
| Domain=example.com | also sent to subdomains; omit it to restrict to the exact host |
Common problems
- A cookie with
SameSite=Nonebut withoutSecureis 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) requireSecure,Path=/and noDomain, which prevents subdomains from overwriting them.
Sources
Related pages
errors · corsblocked by CORS policy: No 'Access-Control-Allow-Origin' headerThe browser blocks a cross-origin response without Access-Control-Allow-Origin. Fix it on the server by sending the header for your origin, or proxy the API.config · httpStrict-Transport-Security (HSTS): max-age, includeSubDomains, preloadStrict-Transport-Security makes browsers use only HTTPS for max-age seconds. includeSubDomains covers subdomains; preload is a commitment that is hard to undo.commands · jwtDecode a JWT from the command line (header and payload)A JWT is three base64url parts joined by dots. Decode the header and payload with Node.js or base64 in one line; decoding is not verifying the signature.