guides · 2026-11-14
Session Cookies Without HttpOnly, Secure and SameSite: What Each Missing Flag Costs You
Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team
The short answer
HttpOnly keeps the cookie out of JavaScript's reach (blunting session theft via XSS), Secure keeps it off plain-HTTP requests (blunting network sniffing), and SameSite keeps it off most cross-site requests (blunting CSRF). A session cookie missing any of the three is missing a specific, named defence — set all three, with SameSite=Lax as the default that fits most apps.
Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.
What is Cookie security flags?
attributes on the Set-Cookie header that instruct the browser how to handle a cookie: HttpOnly (inaccessible to scripts), Secure (HTTPS only), SameSite (cross-site sending rules), plus supporting attributes like Path, Domain and expiry that scope where and how long the cookie applies.
HttpOnly: the flag that assumes XSS will happen
Without HttpOnly, any JavaScript running on your page — including an injected script from an XSS flaw or a compromised third-party widget — can read document.cookie and exfiltrate the session ID, converting a content bug into full account takeover from anywhere. With HttpOnly, the browser sends the cookie with requests but refuses to show it to scripts: the XSS still defaces or acts within the page, but it cannot steal the session and replay it from the attacker's machine. Vibe-Code Audit checks the Set-Cookie header for each flag separately (three distinct LOW findings), because generated and hand-rolled auth code sets cookies by string concatenation and routinely ships one or two of the three.
Secure and the network you do not control
Without Secure, the browser will happily send the cookie over any plain-HTTP request to your domain — a downgrade link, a stray http:// subresource, a captive-portal moment on café Wi-Fi — and anyone on that network path can read it in transit. HTTPS everywhere (with HSTS, per the headers guide) shrinks the window; the Secure flag closes it by making the cookie HTTPS-only, full stop. There is no modern-app reason to omit it: if your site works over HTTPS, Secure costs nothing.
SameSite: the CSRF seatbelt, with one compatibility note
SameSite=Lax (the sane default) withholds the cookie from cross-site POSTs — the exact shape of classic CSRF — while still sending it on top-level navigations, so emailed links to your app arrive logged-in. Strict is stronger and breaks that arrival experience (users landing from external links appear logged out until an internal navigation); None is required for genuinely cross-site embedded contexts (iframes, some SSO and payment flows) and browsers demand Secure alongside it. Choose per cookie with intent: session cookies Lax or Strict, and treat any SameSite=None as a documented exception. Note the interplay: SameSite blunts CSRF but does not replace CSRF tokens on state-changing forms — the scanner's form check exists because defence in depth is the pattern, not either/or.
Setting them so frameworks do not drop them
Set flags where the cookie is created — framework session config (one place) rather than per-handler strings — and verify on the wire: log in against staging and read the actual Set-Cookie response headers, because proxies and framework defaults occasionally strip or override attributes. Audit the supporting cast at the same time: Path scoped as narrowly as the app allows, no overly broad Domain, and a session lifetime that matches your risk (a 30-day session cookie on a finance-adjacent app is a decision, whether or not anyone made it deliberately). Re-check after auth-library upgrades; cookie defaults are exactly the kind of thing major versions change quietly.
Worked example: GoldLeaf CRM's session audit
GoldLeaf CRM (fictional), used by about 340 small sales teams, set its session cookie in a hand-rolled login handler written by an AI assistant: the cookie had Secure but neither HttpOnly nor SameSite, which a scan reported as two separate flag findings. A staging demonstration with a benign injected script read the session cookie and replayed it from a second browser — a full session hijack with no password. Cookie creation moved into the framework's session configuration with HttpOnly + Secure + SameSite=Lax and a 7-day lifetime (down from 30), existing sessions were invalidated at deploy, and the wire check — reading the real Set-Cookie header after login — was added to the release checklist. The replay demonstration then failed at the first step: the script could not see the cookie at all.
Your five-action checklist
- Log in to staging and read the actual Set-Cookie headers for your session cookie; note which of HttpOnly, Secure and SameSite are present.
- Set all three in the framework's central session configuration — HttpOnly on, Secure on, SameSite=Lax unless a documented flow needs otherwise.
- Review the supporting attributes: narrow Path, no unnecessary Domain, and a session lifetime you can justify.
- Invalidate existing sessions when flags change materially, so stolen or long-lived cookies die with the old policy.
- Re-verify the wire headers after every auth or framework upgrade, and keep the three flag checks in your scan routine.
Sources
- OWASP Top 10, the OWASP Foundation's standard awareness list of the most critical web application security risks: owasp.org, 2021
- CWE-89: Improper Neutralization of Special Elements used in an SQL Command, MITRE's weakness entry for SQL injection and its mitigations: cwe.mitre.org, 2026
- OWASP Cheat Sheet Series — Secrets Management, OWASP's best-practice guide to storing, rotating and auditing secrets: cheatsheetseries.owasp.org, 2026
Frequently asked questions
Does HttpOnly break my frontend's access to the session?
Your frontend should never need the session cookie's value — the browser attaches it automatically. Code that reads the cookie in JS usually wants a separate, non-session value (a preference or CSRF token), which belongs in its own non-HttpOnly cookie.
SameSite=Lax or Strict for sessions?
Lax for most apps: it blocks cross-site POST sending (the CSRF shape) while keeping emailed-link arrivals logged in. Strict suits high-sensitivity apps willing to accept the logged-out-arrival quirk.
If I have CSRF tokens, do I still need SameSite?
Yes — defence in depth. Tokens protect the forms you remembered; SameSite protects the endpoint you forgot, and vice versa. Neither is a reason to drop the other.
Why does the scanner rate a missing flag as only LOW?
A single missing flag is a missing layer, not an open door — its severity depends on a partner flaw (XSS for HttpOnly, an HTTP path for Secure, CSRF for SameSite). LOW means 'fix it in the batch', not 'ignore it': the flags are nearly free.
Related guides
- Second-Order Injection: The Payload That Waits in Your Database Until It Reaches a Sink
- What Happens When Your .env File Is Publicly Exposed?
- How an Exposed .git Folder Lets Attackers Download Your Source Code
- Which Security Headers Is Your Website Missing — and What Does Each One Actually Do?
- Why Your Supabase Service Role Key Must Never Appear in Frontend Code
- What to Do in the First Hour After an OpenAI API Key Leaks From Your App
- 7 Security Mistakes AI Coders Keep Making
- Supply-Chain Attacks in the AI-Coding Era
- Secret Hygiene: Stop API Key Leaks
- What Code Scanners Can't Find
- Bolt.new Pre-Deploy Security Checklist
- Cursor-Generated Code Review Checklist
Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.
Informational explainer, not a security guarantee. Scan your code free before every deploy.