Set-Cookie Header Explained
What the HTTP Set-Cookie header does and when it's used.
Published October 14, 2026
Set-Cookie is a response header that asks the browser to store a cookie, with attributes such as Expires, Max-Age, Path, Domain, Secure, HttpOnly and SameSite.
How it works
Each cookie needs its own Set-Cookie header.
The Set-Cookie header is part of the HTTP message and is case-insensitive in name.
In a real exchange
curl -i https://example.com/
Set-Cookie: sid=abc; HttpOnly; Secure; SameSite=Lax; Max-Age=3600
Practical examples
The header
Set-Cookie: sid=abc; HttpOnly; Secure; SameSite=Lax; Max-Age=3600Set or use it in code
res.cookie('sid', id, { httpOnly: true, secure: true, sameSite: 'lax', maxAge: 3600000 })Inspect it
curl -sI https://example.com | grep -i 'set-cookie'Common mistakes
- Missing HttpOnly or Secure on session cookies
- SameSite=None without Secure
- Setting overly broad Domain
Key takeaways
- Set-Cookie: Set-Cookie is a response header that asks the browser to store a cookie, with attributes such as Expires, Max-Age, Path, Domain, Secure, HttpOnly and SameSite.
- Check it in browser DevTools → Network.
- Test with curl -I before deploying.
FAQ
What does SameSite do?
It limits when cookies are sent on cross-site requests, reducing CSRF.
Is Set-Cookie case sensitive?
Header names are case-insensitive; values may not be.