Set-Cookie — security attributes
Stores cookies in the browser — and its Secure, HttpOnly and SameSite attributes are what stand between a session cookie and theft or CSRF.
What it is
Set-Cookie writes a cookie to the browser. Cookies frequently carry session identifiers, so the header's attributes are security-critical: they control whether the cookie is sent over HTTP, whether JavaScript can read it, and whether it accompanies cross-site requests.
Security attributes
- Secure
- The cookie is only sent over HTTPS, never plain HTTP.
- HttpOnly
- JavaScript cannot read the cookie (document.cookie), blocking theft via XSS.
- SameSite=Strict
- Cookie is withheld on all cross-site requests — strongest CSRF protection.
- SameSite=Lax
- Sent on top-level cross-site navigations (GET) but not cross-site subrequests. The modern default.
- SameSite=None
- Sent on all cross-site requests. Requires Secure. Needed for legitimate third-party cookies.
- Path / Domain
- Scope the cookie to a path/domain. Prefer the narrowest scope.
- __Host- prefix
- Enforces Secure, Path=/ and no Domain — the safest cookie configuration.
HTTP RESPONSE HEADER
Set-Cookie: __Host-session=abc123; Max-Age=3600; Path=/; Secure; HttpOnly; SameSite=LaxWhy it matters
HttpOnlyprevents a successful XSS from reading the session cookie, sharply limiting the damage of script injection.Securestops a session cookie from ever traveling over plain HTTP where it could be sniffed.SameSiteis a first-class defense against cross-site request forgery (CSRF), often removing the need for a separate CSRF token on GET flows.
Common mistakes
- Omitting
HttpOnlyon a session cookie, so any XSS can immediately exfiltrate it. - Using
SameSite=NonewithoutSecure, which modern browsers reject — the cookie is silently dropped. - Scoping a cookie to
Domain=.example.comwhen a host-only cookie would do, widening exposure across subdomains. - Not using the
__Host-prefix for sensitive cookies where it would enforce the safest defaults automatically.
How WebInspect checks this
- WebInspect inspects each
Set-Cookieand reports which ofSecure,HttpOnlyandSameSiteare present. - It flags session-like cookies missing
HttpOnlyorSecure, andSameSite=Nonecookies that lackSecure. - It recognizes the
__Host-/__Secure-prefixes and credits their hardened configuration.