Skip to content

Secure Cookie Attributes: HttpOnly & SameSite

Review Secure, HttpOnly, SameSite, and __Host- cookie attributes alongside HSTS and CSP headers to protect session tokens during web pentests.

By BugSnaps · 3 min read · Updated

Add BugSnaps as a preferred source on Google(opens in a new tab)

Want more of our security guides? Select BugSnaps and confirm your choice on Google.

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

Comparison of HTTP cookie security attributes and prefixes
Attribute / PrefixBrowser EnforcementWhat It PreventsWhen It Is Required
SecureBrowser 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.
HttpOnlyBlocks 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=LaxWithholds 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=StrictNever 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- prefixRequires 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

  1. Capture every Set-Cookie header across the full authentication lifecycle: initial landing page, login POST response, token refresh endpoint, password change, and logout.
  2. 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.
  3. Verify that logout and password-reset responses explicitly clear or rotate server-side session state in addition to expiring the cookie in the browser.
  4. 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.

Run a vulnerability scan on your website.

Verify your domain and use MyPentest to check for supported web and API weaknesses. Review findings and coverage; a clean scan does not rule out every CVE.