Every time your server sends a Set-Cookie header, the attributes after the cookie value decide where the browser will send that cookie back and who may read it. A session cookie without Secure can travel over a plain HTTP request. A cookie without HttpOnly can be read by any script running on the page. A cookie without SameSite leaves it to the browser's default whether it rides along on requests that other sites start.
None of these attributes is new or difficult, yet missing flags remain a common finding, usually because a framework default was never changed, TLS ends at a proxy the application does not know about, or a plugin sets its own cookies. This guide explains what each attribute prevents and what it does not, how the __Host- and __Secure- prefixes add browser-enforced rules, the settings in PHP, Node.js, Django, Rails, Laravel, ASP.NET Core and nginx, and how to read your own headers to verify the result. All examples use example.com.
If you arrived here from the Sitelemetry finding http.cookie.flags.missing, section 10 explains exactly what triggers it and what it does not look at.
Scope of this guide
This guide covers cookies visible in public HTTP responses. Sitelemetry reads the Set-Cookie headers of one unauthenticated home page response; it cannot see cookies set after login, by JavaScript or on other pages, and it is not a pentest.
2. Secure: keep the cookie off plain HTTP
RFC 6265 says a cookie with the Secure attribute is sent only over secure channels, which in browsers means HTTPS. Without it, the browser attaches the cookie to any http:// request to your host: an address typed without the scheme before your redirect answers, an old bookmark, an email link, or an image embedded with an http:// URL. That request crosses the network unencrypted, and anyone on the same Wi-Fi or path can copy the session token from it.
Redirecting HTTP to HTTPS does not fix this on its own, because the browser sends the cookie in the first request, before the redirect arrives. HSTS narrows the gap for returning visitors, as the guide to TLS and HSTS explains, but Secure is the attribute that ties the cookie itself to HTTPS.
Points that often surprise people:
- Secure is about confidentiality, not integrity. RFC 6265 notes that a network attacker could historically plant or overwrite cookies from an insecure connection. Modern browsers no longer let
http:pages set cookies with Secure or overwrite existing Secure cookies, according to MDN, and the__Host-prefix in section 5 closes the remaining routes. - Local development. MDN notes that Chrome and Firefox treat
http://localhostas a secure context for this purpose, so Secure cookies usually work in local development without a certificate. - TLS behind a proxy. When a load balancer or CDN ends TLS and forwards plain HTTP to the application, many frameworks believe the request is insecure and skip the Secure flag they would otherwise add. The fix is to tell the framework to trust the proxy's
X-Forwarded-Protoheader, but only when the proxy always sets or replaces that header itself.
3. HttpOnly: keep the cookie away from scripts
HttpOnly tells the browser not to expose the cookie to JavaScript. document.cookie no longer lists it, yet the browser still sends it with every matching request, including fetch() and form submissions. The OWASP Session Management Cheat Sheet recommends it for every cookie that carries a session identifier.
The benefit is specific. If an attacker manages to run a script on one of your pages, through a cross-site scripting bug or a compromised third-party script, they cannot simply read the session token and use it from their own machine later. HttpOnly does not stop that script from sending requests in the visitor's name while the page is open, because the browser attaches the cookie automatically. It reduces the damage of a script injection; it does not replace fixing the injection or a Content Security Policy.
HttpOnly also does not hide the cookie from the visitor: browser developer tools and extensions with the right permissions can still see it. It protects against other people's code on your page, not against the person using the browser.
4. SameSite: decide which requests from other sites carry the cookie
SameSite controls whether the cookie is sent when a request is started by a different site. A site here is the scheme plus the registrable domain, so https://www.example.com and https://app.example.com are the same site, while https://example.com and https://example-pay.net are not. Same-site is broader than same-origin: your subdomains always count as the same site.
Strict: never sent on cross-site requests, not even when a visitor clicks a link to you from another site. They arrive signed out on the first page and appear signed in after the next click. Good for an admin area; awkward for a whole site.Lax: sent when the visitor navigates to your site at the top level with a safe method such as GET, for example by clicking a link, but not on cross-site POST forms, iframes, images orfetch()calls. A sensible default for session cookies.None: sent in every context. Browsers require Secure with it and rejectSameSite=Nonewithout Secure. Use it only for cookies that must work inside third-party embeds.
According to web.dev, Chrome treats a cookie with no SameSite attribute as Lax. Not every browser applies that default, so set the value explicitly rather than relying on it.
Two practical edge cases. First, single sign-on and payment providers sometimes send the visitor back to you with a cross-site POST, for example the OpenID Connect form_post response mode or a SAML POST binding. With Lax or Strict, your session cookie is not attached to that POST, so the return page must not depend on it, or that one cookie needs None; Secure. Second, SameSite is a strong layer against cross-site request forgery, but the OWASP CSRF Prevention Cheat Sheet treats it as defence in depth, not a replacement for CSRF tokens, partly because it does nothing against requests from your own subdomains.
6. Setting the flags in common frameworks
Fix cookies where they are created whenever you can. The application knows which cookies scripts need, which a proxy cannot know.
PHP sessions and setcookie
The session settings are documented in the PHP manual. In php.ini or your pool configuration:
session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = "Lax"
session.use_strict_mode = 1For your own cookies, use the options array of setcookie():
setcookie('prefs', $value, [
'expires' => time() + 2592000,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);Laravel
In config/session.php, keep 'http_only' => true and 'same_site' => 'lax', and set SESSION_SECURE_COOKIE=true in the production environment so that 'secure' is enabled.
Node.js with Express
app.set('trust proxy', 1); // TLS ends at a proxy in front of the app
app.use(session({
name: '__Host-sid',
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: { secure: true, httpOnly: true, sameSite: 'lax', path: '/' }
}));
res.cookie('prefs', value, { secure: true, httpOnly: true, sameSite: 'lax' });Without trust proxy, express-session sees plain HTTP from the proxy and does not send a Secure session cookie at all, which looks like sign-in silently failing.
Django
From the Django settings reference:
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True # default
SESSION_COOKIE_SAMESITE = 'Lax' # default
CSRF_COOKIE_SECURE = True
# only if your proxy always sets or strips this header:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')Ruby on Rails
# config/environments/production.rb
config.force_ssl = true # also marks cookies as Secure
# config/initializers/session_store.rb
Rails.application.config.session_store :cookie_store,
key: '_app_session', secure: true, same_site: :laxASP.NET Core
builder.Services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Cookie.SameSite = SameSiteMode.Lax;
});WordPress
WordPress core sets its login cookies as HttpOnly and marks them Secure when it detects HTTPS. Behind a proxy, make sure WordPress recognises the request as HTTPS. Cookies flagged on a WordPress site often come from plugins or themes, so look up each cookie name to find which component sets it and change that component's settings.
7. Adding flags at the web server, proxy or CDN
When you cannot change the application, for example a packaged product, a reverse proxy can rewrite cookie attributes on the way out. nginx 1.19.3 and later has proxy_cookie_flags in the proxy module:
location / {
proxy_pass http://app_backend;
# every cookie from the backend
proxy_cookie_flags ~ secure httponly samesite=lax;
}
# or only the session cookie by name
# proxy_cookie_flags sessionid secure httponly samesite=lax;The directive applies to responses from the proxied backend; cookies that nginx itself would add elsewhere are not covered. On Apache, mod_headers can edit Set-Cookie headers with a regular expression, but appending text blindly duplicates attributes the application already sets, so test the output carefully. Some CDNs offer response header rules or edge functions that can do the same.
Treat these rewrites as a stopgap with a cost. Applying httponly to every cookie breaks any cookie that front-end code legitimately reads, which is the subject of the next section. Matching cookies by name is safer than a catch-all rule.
8. Cookies that legitimately skip HttpOnly
Not every cookie is a session token. Some are meant to be read by JavaScript:
- CSRF tokens in the double-submit pattern. Django's
csrftokenand Laravel'sXSRF-TOKENare not HttpOnly by default so that front-end code can copy the value into a request header. Django documentsCSRF_COOKIE_HTTPONLY; if you turn it on, your JavaScript must read the token from the hidden form field instead of the cookie. - Consent and preference cookies read by a consent banner or theme switcher.
- Analytics cookies written by a script in the browser. These do not appear in Set-Cookie headers at all, because JavaScript creates them.
The rule of thumb: a cookie that grants access, such as a session, a remember-me token or an API token, must be HttpOnly. A cookie that scripts must read should contain nothing that would let someone act as the user. Every cookie on an HTTPS site should still be Secure, because there is rarely a reason for any of them to travel over plain HTTP. Keep a short inventory with each cookie's name, purpose, owner and expected attributes, so that a scan result can be compared with what you intended.
10. What Sitelemetry checks for cookie flags
The finding http.cookie.flags.missing comes from Sitelemetry's HTTP security headers module. It is a passive check: it requests the home page (root URL) of the scanned origin, follows redirects, and reads every Set-Cookie header on the response it ends on. For each cookie it applies two rules:
- it raises the finding when the header text does not contain
HttpOnly; - when the target you scan is an
https://address, it also raises the finding when the text does not containSecure.
The match ignores case. Each affected cookie produces its own finding, rated medium. The evidence is the first segment of the header, before the first semicolon, which means the cookie's name and its value. The recommended fix is to use HttpOnly, Secure and SameSite for session cookies.
| Set-Cookie seen | Target scanned | Finding raised? | Why |
|---|---|---|---|
sid=…; Path=/ | https:// | Yes | Neither HttpOnly nor Secure |
sid=…; Path=/; HttpOnly | https:// | Yes | Secure missing on an HTTPS target |
sid=…; Secure; HttpOnly | https:// | No | Both present; SameSite is not evaluated |
csrftoken=…; Secure; SameSite=Lax | https:// | Yes | No HttpOnly, even if that is intentional |
sid=…; HttpOnly | http:// | No | Secure is only required for HTTPS targets |
Know the limits. The check does not evaluate SameSite, Domain, Path, expiry or prefixes. It is a text match, so the words appearing anywhere in the line, even in a cookie's name or value, count as present. It sees only cookies sent in that one unauthenticated response: not cookies set on a redirect along the way, after sign-in, on other pages or by JavaScript. It flags intentional exceptions such as CSRF cookies, so compare results with your cookie inventory and verify with the steps in section 9. If the response is a bot challenge, an access denial or an edge error page, the module reports the result as not measured, so cookies set by the protection layer are not flagged.
The module runs in every scan profile and on every plan: Free ($0), Starter ($49/month), Professional ($149/month) and Enterprise ($249/month). It reads only what any visitor receives, so it needs no ownership verification on its own: the free Launch Readiness Snapshot, which you can also open through the security headers checker, runs it without signup, and a Free-plan security audit runs it even before you verify the site. A security audit that also includes checks that need ownership proof, as paid-plan audits do by default, asks you to verify the site first. For the other headers on the same response, see also the security headers check guide. Sitelemetry is an automated audit tool, not a penetration test or a compliance attestation. The website security audit guide places cookie flags among the other checks, and pricing lists what each plan adds.
Common questions
What does "cookie without secure flag" mean?
The Set-Cookie header lacks the Secure attribute, so the browser will also send that cookie over plain HTTP requests to your host, for example before your HTTP to HTTPS redirect answers. Anyone on the network path can read it there. Add Secure to every cookie on an HTTPS site, and make sure a proxy that ends TLS does not make your framework skip it.
Should every cookie be HttpOnly?
Every cookie that grants access should be: sessions, remember-me tokens and API tokens. Some cookies are designed to be read by scripts, such as double-submit CSRF tokens or consent preferences. Those should hold nothing that lets someone act as the user. Secure, by contrast, belongs on every cookie of an HTTPS site.
Which SameSite value should I use for a session cookie?
Lax is a sensible default: the cookie arrives when visitors follow a link to you but not on cross-site POSTs, iframes or background requests. Use Strict for sensitive areas such as an admin panel if signed-out arrivals from links are acceptable. Use None, which requires Secure, only for cookies that must work inside third-party embeds or cross-site POST returns.
Do I still need Secure if my site redirects to HTTPS and sends HSTS?
Yes. The redirect arrives only after the browser has sent the first HTTP request, cookies included. HSTS protects returning visitors whose browser already stored the policy, but Secure ties the cookie itself to HTTPS in every case. The two work together; neither replaces the other.
Does Sitelemetry check SameSite or the __Host- prefix?
No. The http.cookie.flags.missing check looks for HttpOnly on every cookie and for Secure when the scanned target is an https:// address, in the Set-Cookie headers of one unauthenticated response from the site's home page. Its recommended fix mentions SameSite, but SameSite, Domain, Path and prefixes are not evaluated, so check those with curl and browser developer tools.
Sources & further reading
- RFC 6265: HTTP State Management Mechanismwww.rfc-editor.org
- MDN: Set-Cookie headerdeveloper.mozilla.org
- OWASP Session Management Cheat Sheetcheatsheetseries.owasp.org
- OWASP Cross-Site Request Forgery Prevention Cheat Sheetcheatsheetseries.owasp.org
- web.dev: SameSite cookies explainedweb.dev
- nginx: ngx_http_proxy_module (proxy_cookie_flags)nginx.org
- Django settings referencedocs.djangoproject.com
- PHP manual: session runtime configurationwww.php.net
Prepared by the Sitelemetry editorial team. Explore the linked sources for further detail.



