Transport & CookieResponse Header

Set-Cookie

Transfers session cookies from server to client with security flags controlling JavaScript access, cross-site transmission, and SSL encryption.

Recommended Production Value
Essential (A+)
session_id=xyz; Secure; HttpOnly; SameSite=Lax; Path=/

Production Server Implementation

NGINX Configuration Snippet
proxy_cookie_flags ~ nosecure samesite=lax httponly;

Directives & Syntax Breakdown

HttpOnly

Prevents client-side scripts (document.cookie) from accessing the cookie, blocking XSS session hijacking.

Secure

Forces the cookie to only be transmitted over encrypted HTTPS connections.

SameSite=Lax

Protects against Cross-Site Request Forgery (CSRF) by withholding cookie on cross-site requests.

SameSite=Strict

Maximum CSRF protection: never sends cookie on any third-party link navigation.

Common Security Hazards & Pitfalls

  • β€’Omitting HttpOnly allows any minor XSS vulnerability to compromise the entire user session.
  • β€’SameSite=None MUST be accompanied by the "Secure" flag, otherwise modern browsers reject the cookie.
Frequently Asked Questions

Set-Cookie - Questions & Answers

Common implementation questions, browser enforcement rules, and debugging.

The browser may transmit the session cookie in plaintext if the user accesses an HTTP URL, exposing the session to Wi-Fi eavesdroppers.