Session cookies and tokens
The cookie or token that keeps a person signed in between pages.
In one line
Can keep you signed in between pages with a small ID stored in your browser
The cookie or token that keeps a person signed in between pages.
A random session ID (OWASP: at least 64 bits of entropy) ties each request to an account. Whoever holds it is the person. Timeouts are 2 to 5 minutes idle for high risk apps and up to 30 minutes for low risk, per OWASP.
What it can and can't do
What the user does: Nothing extra. It starts when you sign in and continues as you click around
It can
- Remember who you are on every page you open until you sign out or it times out
- Keep items in your cart or settings tied to your signed in session
- Sign you out automatically after a set time, often 2 to 30 minutes of no activity
- Treat anyone who holds that ID as you
It cannot
- Know who you are after the session ends or you clear cookies
- Follow you onto other sites; the ID belongs to this site
- Show your password; only a random session ID is stored
- Stay valid after you sign out on a well built site
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 1 | 2008-12-11 | :Standard in every browser |
| Edge | Supported | 1 | Not listed | :Standard in every browser |
| Firefox | Supported | 1 | 2004-11-09 | :Standard in every browser |
| Safari | Supported | 1 | 2003-06-23 | :Standard in every browser |
| Safari on iPhone | Supported | 1 | 2007-06-29 | :Standard in every browser |
| Chrome on Android | Supported | 1 | Not listed | :Standard in every browser |
| Samsung Internet | Supported | 1 | 2013-04-27 | :Standard in every browser |
How a site asks for it
| API | Set-Cookie: sid=...; HttpOnly; Secure; SameSite=Lax; __Host- prefix |
| How access is granted | none |
| What the user sees | None |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| How long it lasts | Session until browser close, or persistent up to 400 days. Idle and absolute server timeouts apply |
| How to take it back | Clear site data, browser privacy settings |
| Inside an iframe | Not listed |
Data you get
What comes back: Session ID
Shape: string
How often: per request
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
entropy | integer | bits | at least 64, 128 recommended | exact |
Technical limits
- HttpOnly hides it from scripts
- __Host- prefix forces Secure, Path=/ and no Domain
- Chrome caps lifetime at 400 days
- Browser restore can bring session cookies back after restart
The story
What it is
A small token that keeps you signed in as you move from page to page.
For you
You sign in once and stay signed in while you click around, add things to a cart or play a web game. You never see the token. If it times out you are asked to sign in again.
For makers
Every logged in site needs a way to remember who you are between clicks. Makers also use the same token to count active users, limit abuse, and tie purchases and saved progress to the right account.
Where you see it
| Type | Example | Apps |
|---|---|---|
| games | A browser game keeps a player signed in so a multiplayer match, friends list and in game purchases all point to the same account. | Roblox, Wordle (NYT), Poki |
| shopping | A cart stays full while a shopper browses for an hour, and the checkout page knows who they are. | Amazon, Etsy |
| banking | A bank signs a person out after a few minutes of quiet and ties each session to one browser to block hijacking. | None named |
| video | A video call web app keeps the host signed in while a meeting runs, so screen sharing and chat stay linked to their account. | Google Meet, Zoom |
| security | A fraud engine watches for a session token suddenly used from a different country or device, which hints at theft. | None named |
| analytics | A product team counts how many signed in people are active each day by counting session tokens. | Google Analytics |
| creative | A design web app keeps every browser tab signed in so edits sync live to a teammate's view. | Figma, Canva |
Risks
- Stolen token equals stolen account
- Long sessions on shared computers
Good uses and abuse
Legitimate uses
- Keeping a person signed in
Known abuse
- Session theft and fixation
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 5 of 5 | How revealing the data is |
| Utility | 5 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | Not rated | Rough identifying entropy, when known |
History
- 2020-02, Chrome 80: SameSite=Lax default reduced CSRF
Related capabilities
Related
- First party cookies. Can keep small notes in your browser and get them back on every visit
- Device Bound Session Credentials. Can tie your sign in to this device so copied cookies stop working elsewhere
Sources
How well checked: Based on official documentation.