Skip to main content
HeadersHigh PriorityFree

Set-Cookie Security Flags Explained

Updated November 2026·SecScanner Team

Cookie security attributes (Secure, HttpOnly, SameSite) protect session cookies from theft and cross-site attacks.

42% of the 101 most-visited sites we scan fail this check. See the full data.

Results in 1–3 minutes · Free · No signup required

Want the result for your own site? Free Cookie Security Checker — paste your domain, get the report.

Why It Matters

Insecure cookies can be stolen via XSS (without HttpOnly), transmitted over HTTP (without Secure), or exploited in CSRF attacks (without SameSite). Session hijacking can give attackers full access to user accounts.

How We Check

We analyze Set-Cookie headers for Secure, HttpOnly, and SameSite attributes. We also check for cookie prefixes (__Host-, __Secure-) and appropriate expiration settings.

Good vs Bad Values

Good and bad values for Set-Cookie headers
ValueVerdictWhy
__Host-session=…; Secure; HttpOnly; SameSite=Lax; Path=/GoodThe reference session cookie: HTTPS only, hidden from JavaScript, limited cross-site sending, locked to the exact host.
session=…; Secure; HttpOnly; SameSite=StrictGoodStrongest CSRF protection. Users arriving from external links start logged out on the first request.
session=…; Secure; HttpOnly (no SameSite)WeakModern browsers default to Lax, but older ones send the cookie cross-site. State the attribute explicitly.
session=…; Secure; SameSite=Lax (no HttpOnly)BadAny XSS can read document.cookie and steal the session.
session=…; HttpOnly (no Secure)BadThe cookie is sent over plain HTTP too, where anyone on the network can capture it.
SameSite=None without SecureBadBrowsers reject the cookie outright. SameSite=None is only valid together with Secure.
Domain=example.com on a session cookieWeakShares the cookie with every subdomain, including ones that are less carefully secured. Omit Domain to keep it host-only.
theme=dark; Secure; SameSite=Lax (no HttpOnly)GoodA preference cookie that your own JavaScript must read. HttpOnly is for session and auth tokens.

How to Fix

Set all sensitive cookies with: Set-Cookie: session=value; Secure; HttpOnly; SameSite=Lax; Path=/. Use __Host- prefix for session cookies when possible.

Nginx (reverse proxy, 1.19.3+) — add flags to cookies set by the upstream app:

proxy_cookie_flags ~ secure httponly samesite=lax;

Apache (requires mod_headers) — append flags to every cookie; make sure the app does not already set them to avoid duplicates:

Header always edit Set-Cookie ^(.*)$ "$1; Secure; HttpOnly; SameSite=Lax"

Next.js (route handler or server action):

cookies().set("session", token, { httpOnly: true, secure: true, sameSite: "lax", path: "/" });

Express: res.cookie("session", token, { httpOnly: true, secure: true, sameSite: "lax" }). PHP: in php.ini, set session.cookie_secure=1, session.cookie_httponly=1 and session.cookie_samesite=Lax.

Which cookies need which flags. Session and authentication cookies: Secure, HttpOnly and SameSite=Lax (or Strict). CSRF tokens read by JavaScript: Secure and SameSite, but not HttpOnly. Preference cookies: Secure and SameSite=Lax are still good practice. Only use SameSite=None; Secure for cookies that must work inside third-party iframes.

Verify by listing every cookie your site sets, not just the one on the home page:

curl -sI https://example.com/ | grep -i '^set-cookie'
curl -sI https://example.com/login | grep -i '^set-cookie'

Common Mistakes

  • Setting flags only in the login handler. Every code path that issues or refreshes a session cookie needs the same attributes.
  • Using `Secure` behind a TLS-terminating proxy without telling the app. If the framework thinks the request is HTTP, it may skip the flag; set the trust-proxy option.
  • Using `__Host-` with a `Domain` attribute or a `Path` other than `/`. The browser silently discards the cookie.
  • Long-lived session cookies (`Max-Age` of a year) with no server-side expiry or rotation after login.
  • Not regenerating the session identifier at login. An attacker who planted a known session cookie before sign-in (session fixation) keeps access, no matter how strict the flags are.

Frequently Asked Questions

What is Set-Cookie headers?

Cookie security attributes (Secure, HttpOnly, SameSite) protect session cookies from theft and cross-site attacks.

Why does Set-Cookie headers matter for website security?

Insecure cookies can be stolen via XSS (without HttpOnly), transmitted over HTTP (without Secure), or exploited in CSRF attacks (without SameSite). Session hijacking can give attackers full access to user accounts.

How do I fix Set-Cookie headers issues?

Set all sensitive cookies with: Set-Cookie: session=value; Secure; HttpOnly; SameSite=Lax; Path=/. Use __Host- prefix for session cookies when possible.

Related Security Checks

Related Tool

Cookie Security Checker

Run all 2 related checks with our free cookie security checker

Check Your Website Now

Run a free security scan to check for Set-Cookie headers issues and 61 other security checks.

Scan Your Website Free