Skip to main content
All Terms Glossary

Secure Cookies

Definition

Secure cookies are HTTP cookies with special attributes that enhance security. The 'Secure' flag ensures cookies are only sent over HTTPS connections, while 'HttpOnly' prevents JavaScript access to cookies, protecting against XSS attacks. The 'SameSite' attribute helps prevent CSRF attacks by controlling how cookies are sent in cross-site requests.

What secure cookies are

Secure cookies are ordinary HTTP cookies hardened with protective attributes. The Secure flag tells the browser to send the cookie only over HTTPS, never over plain HTTP. HttpOnly hides the cookie from JavaScript, so document.cookie cannot read it. SameSite (Lax, Strict, or None) controls whether the cookie is attached to cross-site requests, which limits its use in cross-site request forgery. Further hardening includes host-only or __Host- and __Secure- name prefixes, tight Path and Domain scoping, and short expirations. Together these attributes shrink how, when, and by whom a cookie, often a session identifier, can be accessed or replayed.

Why the attributes matter

Session cookies are high-value: whoever holds one can often act as the logged-in user. Each attribute closes a specific theft path. Without Secure, a single request over HTTP can leak the cookie to a network eavesdropper. Without HttpOnly, any successful cross-site scripting payload can read the cookie and exfiltrate it. Without SameSite, a malicious site can silently trigger authenticated requests in the victim's browser. None of these attributes is sufficient alone; a cookie needs the right combination for its purpose. Getting them right is one of the cheapest and most effective steps in web session security, and misconfiguration is a common finding in audits.

Applying secure cookies in practice

Set Secure and HttpOnly on every session and authentication cookie, choose SameSite=Lax or Strict unless a genuine cross-site need forces None (which then requires Secure), and prefer the __Host- prefix for session cookies to lock down domain and path. Combine this with HTTPS everywhere and HSTS. Attributes limit exfiltration but do not stop the injection that steals a cookie in the first place: a cross-site scripting flaw can still perform actions inside the session even without reading the cookie. cside detects and can block malicious script behaviour at the payload level, addressing the injection route that cookie flags alone leave open.

Definition

Does the Secure flag encrypt the cookie's contents?

No. Secure only controls transport: it stops the browser from sending the cookie over unencrypted HTTP. The value itself is not encrypted or signed by the flag. If the contents are sensitive, the server must encrypt or sign them separately, or, better, store only an opaque, unguessable session identifier.

Definition

How does SameSite differ from HttpOnly and Secure?

They target different threats. Secure governs which transport carries the cookie, HttpOnly governs whether JavaScript can read it, and SameSite governs whether the cookie rides along on cross-site requests. SameSite mainly mitigates cross-site request forgery, while HttpOnly mainly mitigates theft via cross-site scripting. Robust cookies usually set all three.

Got more questions

Talk to a security expert

We answer client-side security questions every day. Bring yours.

Book a demo

Want to walk through this with an engineer?

Thirty minutes, on your own site. Not a slide deck.

We'll show you:

Which third-party scripts are running on your site right now
Where you stand on PCI DSS 6.4.3 and 11.6.1
How much of your traffic is bots and AI agents

Rather just send a question?

Finding open slots…

Real humans only. We'd know.

Having trouble booking? Open scheduler in a new tab

What are you trying to solve?

Tell us in a line and we'll come back with something useful, not a generic pitch.

We usually help with:

Seeing which third-party scripts run on your site
PCI DSS 6.4.3 and 11.6.1 evidence
Bots, AI agents and account takeover

Prefer to just book a time? Pick a slot instead