Secure Cookie Flag (Secure Flag)
Why You Should Care About Secure Flag
Without the Secure flag, a cookie set over HTTPS can still be sent over HTTP if the user navigates to or is redirected to an HTTP URL. An attacker performing a MITM attack could downgrade the connection to HTTP and capture the cookie in transit. HSTS mitigates this for the domain itself, but the Secure flag provides defense at the cookie level.
The Secure flag should be set on all session cookies and any cookies containing sensitive data. On sites that exclusively use HTTPS (which should be all sites), there is no reason not to set the Secure flag on every cookie.
Note that the Secure flag does not encrypt the cookie value - it only restricts the cookie to HTTPS connections. The cookie value is still visible in browser developer tools and to JavaScript (unless HttpOnly is also set). For storing sensitive data, encrypt the cookie value server-side or use server-side sessions.
Checking Your Setup
A security audit checks the Secure flag on all cookies. Verify it is set on session cookies and any cookies containing tokens, identifiers, or sensitive data. If your site uses HTTPS exclusively (as it should), set Secure on all cookies.
Run a Security Audit