During a web application penetration test, missing cookie flags are among the most common findings—yet security reports often list them without explaining which cookies actually require protection or how browsers enforce each directive. A session identifier or CSRF token stored in a misconfigured Set-Cookie header has a very different risk profile from an anonymous UI theme preference cookie.
Set-Cookie security attributes and prefix rules at a glance
| Attribute / Prefix | Browser Enforcement | What It Prevents | When It Is Required |
|---|---|---|---|
| Secure | Browser transmits the cookie only over encrypted HTTPS connections. | Plaintext session interception on unencrypted HTTP requests. | Mandatory on all session, authentication, CSRF, and sensitive state cookies. |
| HttpOnly | Blocks client-side scripts from reading the cookie via document.cookie. | Direct session-cookie exfiltration during a Cross-Site Scripting (XSS) payload. | Mandatory on server-read session cookies; omit only if client JS must read a non-session value. |
| SameSite=Lax | Withholds cookie on cross-site subrequests (POST, fetch, XHR) but sends on top-level GET navigations. | Baseline Cross-Site Request Forgery (CSRF) on state-changing POST endpoints. | Recommended default for general authenticated web session cookies. |
| SameSite=Strict | Never sends the cookie on cross-site requests, including top-level link clicks. | Cross-site navigation leakage and GET-based state-change triggers. | High-sensitivity admin consoles or step-up authentication cookies. |
| __Host- prefix | Requires Secure, Path=/, and forbids a Domain attribute. | Cookie tossing and subdomain session-fixation attacks from sibling hosts. | Best practice for host-bound primary session identifiers. |
Why the Secure attribute and __Host- prefix matter even when HSTS is enabled
Engineers sometimes ask whether the Secure cookie attribute is redundant when a site redirects HTTP to HTTPS or emits a Strict-Transport-Security (HSTS) header. It is not redundant. Without the Secure attribute, a browser whose HSTS cache has expired—or a client connecting to a non-HSTS sibling subdomain when a cookie has a broad Domain=.example.com scope—will transmit the cookie in cleartext on the very first HTTP request before receiving the 301 redirect.
Even more importantly, standard cookies scoped with Domain=example.com are shared across every subdomain, and any sibling subdomain can overwrite cookies for the parent domain (a technique known as cookie tossing). Binding your session cookie to the __Host- prefix forces the browser to reject the cookie unless it is set over HTTPS, has Path=/, and omits the Domain attribute entirely—isolating the session strictly to the origin host.
How to verify cookie attributes and defensive headers in staging
- Capture every Set-Cookie header across the full authentication lifecycle: initial landing page, login POST response, token refresh endpoint, password change, and logout.
- Classify each cookie by purpose: authentication session, refresh token, CSRF token, or non-sensitive UI preference. Evaluate risk based on the cookie's function rather than treating every cookie identically.
- Verify that logout and password-reset responses explicitly clear or rotate server-side session state in addition to expiring the cookie in the browser.
- Pair cookie hardening with Strict-Transport-Security (HSTS), Content-Security-Policy (CSP), X-Content-Type-Options: nosniff, and explicit CORS origin allowlists.
MyPentest inspects Set-Cookie attributes, session rotation, HSTS, CSP, and CORS headers automatically on verified domains. Start with a free scan and review the exact HTTP response headers in your report.