What Are Secure Cookies, and How Do They Work? (Explained Clearly) - Secure, HttpOnly, and SameSite
Secure cookies explained: Learn how session cookies keep you signed in, what Secure, HttpOnly, and SameSite protect, and how to check cookies in Chrome.
👉 Master your Security+ skills with Pluralsight here: Pluralsight
You’ll learn how secure cookies keep you signed in, what the Secure, HttpOnly, and SameSite settings protect, and where those protections stop. You’ll also see how to use Chrome DevTools to check whether your browser sent a session cookie.
Chapters: 0:00 Intro 0:11 How does a cookie keep you signed in? 1:07 What do Secure, HttpOnly, and SameSite actually protect? 2:31 How can you check whether a secure cookie was sent? 3:37 Outro
Disclaimer: Only test sites you own or have permission to test. Keep live session tokens out of screenshots.
Affiliate notice: Some links may earn a commission. Thanks for your support.
Key Takeaways
A session cookie keeps you signed in. The browser sends the session token with eligible requests, and the server checks whether the session is still valid. Treat live tokens like passwords.
Secure, HttpOnly, and SameSite do different jobs.Secure limits transmission to HTTPS in normal production use but doesn’t encrypt the stored cookie. HttpOnly blocks JavaScript from reading it, and SameSite limits when it’s sent across sites.
Choose the SameSite setting based on how users reach your site.Strict excludes cross-site requests, Lax allows typical top-level visits from external links, and None allows cross-site use but requires Secure.
Cookie flags don’t replace server-side protections. Issue a fresh session ID at login, enforce timeouts, and invalidate the session on logout. Keep separate defenses against XSS and CSRF.
A stored cookie isn’t necessarily a sent cookie. In Chrome DevTools, check Application → Cookies for its settings and Network → request → Cookies to see whether it was sent. Redact live values before sharing screenshots or logs.
👉 Put these concepts into practice with Pluralsight: work through guided cybersecurity labs, get feedback, and use practice exams to focus your certification prep.
A secure cookie is an HTTP cookie with the Secure attribute. On a typical production website, that tells the browser to send the cookie only over HTTPS. HTTPS encrypts the connection, but Secure does not encrypt the stored cookie, hide it from JavaScript, or determine whether it can be sent in a cross-site request. Those last two jobs belong to HttpOnly and SameSite.
How a session cookie keeps you signed in
When you open another message in your inbox, you don't have to enter your password again. Each HTTP request is independent, but your browser can send a that lets the server recognize your signed-in session.
FAQ
Quick answers to the questions people usually ask about this topic.
Do I still need the Secure flag if my website already uses HTTPS?
Yes. HTTPS protects a connection when it is used, while Secure tells the browser not to attach the cookie to a plain HTTP request. An HTTP-to-HTTPS redirect comes after the initial request, so it isn't a substitute for the Secure flag.
Why does a Secure cookie work on localhost but not on my HTTP staging site?
Browsers can make an exception for localhost, allowing Secure cookies during local development without HTTPS. A regular staging hostname does not get that exception. Use HTTPS on staging to test the same cookie behavior you expect in production. See MDN's Set-Cookie reference for details.
Why can I see a session cookie in Chrome DevTools if it is HttpOnly?
HttpOnly blocks page JavaScript from reading the cookie through APIs such as document.cookie; it doesn't hide the cookie from the person using the browser. Chrome DevTools can still display it, so redact the value before sharing screenshots or logs.
Does closing my browser log me out if the site uses a session cookie?
Not necessarily. A cookie without Expires or Max-Age is meant to last for the browser session, but session restore can bring it back. Also, closing the browser does not necessarily end the session on the server. To end access on a shared device, use the site's sign-out button rather than relying on closing the window.
Why might sign-in work in a full browser tab but fail inside an iframe?
If the iframe is embedded on a different site, the browser treats its requests as cross-site. SameSite=Lax can allow a session cookie on a top-level navigation to the sign-in site but generally won't send it inside that iframe. Even with SameSite=None; Secure, browser privacy controls can block or partition the cookie.
How can I practice checking session cookies and build broader application security skills?
Start on a site you own or have permission to inspect: use Chrome DevTools to compare the cookie attributes stored by the browser with the cookies sent on a request. For more structured practice, try Pluralsight for guided cybersecurity labs with feedback, assessments to identify knowledge gaps, and practice exams to focus your certification prep.
Some links may earn a commission. Thanks for your support.
Watch in the video playerOpen the dedicated player for this video.
session cookie
A cookie is a name-value pair the browser stores along with rules for when to send it. Not all cookies are login credentials: some remember a language preference, save a consent choice, or keep track of a guest shopping cart. A login cookie, by contrast, often holds a session token. In a common setup, that token is an opaque session ID: a reference to a record on the server, not a copy of your password or profile.
Here's what happens in a typical sign-in:
You sign in over HTTPS. The server creates a fresh authenticated session ID rather than reusing the pre-login ID.
The server sets the cookie. It sends a Set-Cookie response header with the value and the rules the browser should apply.
The browser sends the cookie back. On a later request that meets those rules, the browser automatically includes the name and value in the Cookie request header.
The server checks the session. It verifies that the session is still valid and checks whether the user is authorized to perform the requested action.
For example, a fictional site might respond with this header:
On an eligible request, the browser sends only the name and value. It doesn't send the attributes back:
Cookie: __Host-session=example-opaque-id
A still-valid session token can stand in for the original sign-in. If someone obtains a bearer session token, they may be able to act as the signed-in user without reentering the password or completing MFA again.
Secure vs. HttpOnly vs. SameSite
These attributes answer three different questions: Is the connection HTTPS? Can page scripts read the cookie? Can the browser send it in a cross-site context?
Attribute
What it controls
What it doesn't do
Secure
Keeps the browser from sending the cookie over plain HTTP in normal production use.
Doesn't encrypt the stored value or force the browser to switch to HTTPS. HSTS is a separate policy for requiring HTTPS.
HttpOnly
Prevents page JavaScript from reading the cookie through APIs such as document.cookie.
Doesn't stop the browser from attaching the cookie to eligible requests triggered by JavaScript.
SameSite
Limits when the browser includes the cookie in a cross-site request.
Doesn't replace server-side protections against cross-site request forgery (CSRF).
A cookie can use all three attributes because each protects a different part of the session. The MDN Set-Cookie reference documents how browsers apply these and other cookie attributes.
SameSite settings: Strict, Lax, and None
Setting
When the browser can send the cookie
SameSite=Strict
Only in same-site contexts. When you first arrive from an external link, the cookie may be absent, making you appear signed out even though your session is still valid.
SameSite=Lax
In same-site contexts and on typical top-level cross-site navigations using a safe method such as GET. Clicking an external link that opens the site as a full page is a common example. Cross-site iframe requests and cross-site POST requests generally don't qualify.
SameSite=None
In cross-site contexts as well as same-site ones, provided the cookie also has Secure. Browser privacy settings can still block or partition third-party cookies.
How cookie scope affects which requests qualify
SameSite isn't the only check. If the server omits Domain, the cookie is host-only: the browser sends it only to the host that set it. For example, https://shop.example.com and https://accounts.example.com are same-site because they share a scheme and registrable domain, but a host-only cookie set by shop.example.com isn't sent to accounts.example.com.
Path further filters which URL paths receive the cookie, but it isn't a security boundary between apps on the same host. In supporting browsers, the __Host- prefix in the example requires Secure, Path=/, and no Domain attribute. It doesn't add HttpOnly or SameSite automatically.
What secure cookies don't prevent
Cookie attributes limit how a token is exposed or sent. They don't fix application vulnerabilities or decide when a session should end.
Session hijacking: If a valid token is exposed, cookie flags don't make the exposed copy unusable. Server-side timeouts and revocation limit how long it can be used.
The browser and server also keep two separate clocks. Cookie attributes such as Max-Age and Expires govern how long the browser retains the cookie. The server determines whether the session is valid, using controls such as idle and absolute timeouts. Deleting the cookie from your browser only removes your local copy. Proper logout invalidates the session on the server so another copy no longer works. See the OWASP Session Management Cheat Sheet for more on session expiration and logout.
How to check whether Chrome sent a secure cookie
On a site you own or have permission to inspect, use Chrome DevTools to check what the browser stored and what it sent. Those are two different checks.
Check storage. Open Application → Storage → Cookies and select the site. Find the session cookie and inspect its , , , domain, and path settings.
Treat live session values like passwords: redact them from screenshots and shared logs.
Practice application security with guided labs
The free series explains how browser and server controls work together. If you're ready to apply those concepts, Pluralsight offers guided cybersecurity labs with feedback, assessments to identify gaps, and practice exams to focus your certification prep.
Session fixation: The application should issue a fresh session ID at login and when privileges change, then invalidate the old ID. The Secure flag can't compensate for reusing a pre-login ID.
Cross-site scripting (XSS):HttpOnly blocks direct cookie reads through page APIs, but a script running on the site can still trigger requests that the browser sends with the cookie. Preventing XSS is a separate job.
Cross-site request forgery (CSRF): An unintended authenticated request doesn't require anyone to read the cookie. SameSite reduces cross-site cookie inclusion, but server-side defenses such as CSRF tokens still matter. GET requests shouldn't change application state.
Secure
HttpOnly
SameSite
Check the request. Open Network, select the request you're investigating, and open its Cookies view. Look for the session cookie among the cookies sent with that request.
Check what happened next. If the cookie was stored but wasn't sent, compare the request's scheme, host, path, and cross-site context with the cookie's rules. If the cookie was sent but the request still failed, check whether the server accepted the session and authorized the action.
Affiliate link — I may earn a commission at no additional cost to you.
Jay's Recommendation
Turn understanding into hands-on confidence
You've built the foundations. Pluralsight adds opportunities to practice in guided security labs, get feedback, and check your knowledge with assessments and practice exams, so your next step is more than another video.
🛠Put concepts to workBuild practical skills with guided security labs and feedback.
🎯Find your weak spotsUse assessments to focus on what needs more work.
📝Check your understandingUse practice exams to guide your certification preparation.
🧭Give study sessions directionOrganize further learning with curated paths and progress tracking.