Choose your depth. Learn at your own pace.
Understand it
A cookie is a small piece of data a browser stores and sends with matching requests. A session is a way for a service to remember an interaction or signed-in identity. A common design stores the session on the server and puts only a random session identifier in a cookie.
The identifier works like a claim ticket. If someone steals a usable session ticket, they may be able to act as its holder without repeating the password step. That is why signing out and protecting session storage matter even when MFA protects sign-in.
Under the hood
The server can return Set-Cookie with attributes that constrain use. Secure limits sending to secure transport; HttpOnly prevents ordinary script access to that cookie; SameSite influences cross-site sending. Domain and Path affect scope but are not a complete authorization boundary.
Rotate the session identifier after authentication and privilege changes. Use idle and absolute timeouts appropriate to the application and invalidate state on logout. Cookies are sent automatically, so state-changing requests need CSRF protections suited to the architecture.
Practitioner perspective
Review the entire session lifecycle: creation, rotation, parallel sessions, logout, recovery, revocation and device loss. A server that merely deletes a browser cookie at logout may leave copied identifiers valid if server state remains active.
Log creation and revocation events using a non-sensitive correlation value rather than raw session identifiers. HttpOnly reduces one route of token theft but does not stop injected script from issuing actions through the user’s browser.
Watch it work
A fictional, simplified model. Select a component to inspect it, or follow the steps in order.
How credentials are checked
See the difference between storage, proof, validation and authorization.
An opaque cookie identifies server-side session state.
How to use this example
Select Next step to read at your own pace, or Animate step to watch one exchange. Nothing advances until you choose.
What it means
Everyday example
State in this scenario
Inspect components & read every step
- Client
A program that asks another system for information or an action.
Example: A shopping app requests a list of products from a service.
- Verifier
The system checking whether the presented proof is acceptable.
Example: A sign-in service checks a submitted password against its stored password verifier.
- Credential store
Storage for authentication-related records. It should not hold passwords as readable text.
Example: A service stores salted password hashes and account information.
- Resource
The information or action someone wants permission to use.
Example: A private document or an account setting is a resource.
JWT validation
A readable token is not a trusted token; validate claims before authorization.
- Client Verifier: Signed token. The request includes a token, not its signing key.
- Credential store Verifier: Trusted public key. Resolve trusted verification material; this may be cached.
- Verifier Resource: Validated claims. Check issuer, audience and lifetime, then evaluate permissions.
- Resource Client: Allowed response. Only an authorized operation returns protected data.
Server session
An opaque cookie identifies server-side session state.
- Client Verifier: Session cookie. The browser sends an opaque session identifier.
- Verifier Credential store: Lookup session. The service reads the associated state.
- Credential store Verifier: User + expiry. Expiry and revocation affect the result.
- Verifier Resource: Identity context. Resource authorization is still required.
Password hashing
Use a password KDF such as Argon2id with a unique salt and suitable cost.
- Client Verifier: Password over TLS. The verifier receives the candidate in a protected connection.
- Credential store Verifier: Salt + KDF settings. Retrieve the stored salt, parameters and verifier.
- Verifier Credential store: Compare verifier. Compare computed and stored verifier safely; do not store plaintext.
- Verifier Client: Decision. Apply rate limits and additional factors where required.
Refresh token
Renewal is a separate credential flow, not an extension of an expired access token.
- Client Resource: Expired token. The resource rejects an expired access token.
- Client Verifier: Refresh credential. The client presents its refresh credential to the authorization server.
- Verifier Client: New access token. Issue a new token only after the refresh policy succeeds.
- Client Resource: Retry with token. The resource validates the new token and requested permissions.
API key
An API key is a credential with scope, expiry and revocation policy—not necessarily a user identity.
- Client Verifier: API key. The client presents a secret credential over TLS.
- Verifier Credential store: Lookup policy. Check status, expiry and configured permissions.
- Verifier Resource: Scoped caller. Authorize this operation under the credential’s policy.
Authorization failure
Authentication can succeed while the requested object remains forbidden.
- Client Verifier: Valid credentials. The verifier establishes who the caller is.
- Verifier Resource: Other user’s object. The application checks the target owner and action.
- Resource Client: 403 · denied. Protected content is not returned.
Fictional teaching trace. One moving dot represents an exchange, not a measured network capture.
Open the detailed lesson walkthrough
Explore the system
Sign in
The server authenticates the user and creates session state.
Read every step without animation
Active session
- Sign in. The server authenticates the user and creates session state.
- Cookie. The browser receives an opaque session identifier.
- Next request. The browser sends the cookie to the matching service.
- Session lookup. The server finds active state and continues with permission checks.
The cookie connects requests; authorization still applies.
Revoked session
- Logout. The server invalidates the session state.
- Copied identifier. A previously copied identifier is presented again.
- Lookup fails. No active session is found.
- Reauthenticate. Protected access requires a new valid sign-in.
Server-side invalidation closes this replay path.
Attack view
A fictional stolen session identifier is replayed. The visual contrasts a still-active session with one the server has invalidated.
Defender view
- Use Secure, HttpOnly and appropriate SameSite attributes.
- Rotate and revoke sessions at relevant identity events.
- Apply CSRF defenses and prevent script injection independently.
Common mistakes
- Cookies and sessions are not synonyms.
- HttpOnly does not make XSS harmless.
Check your understanding
Active recall: explain this idea in 30 seconds
A cookie is a small piece of data a browser stores and sends with matching requests. A session is a way for a service to remember an interaction or signed-in identity. A common design stores the session on the server and puts only a random session identifier in a cookie.
Now give an example and name one limitation. Revisit the explanation if you get stuck.
Primary sources
Original explanations informed by these specifications and official resources. Source versions and lesson review are separate from product updates.
Content reviewed 2026-09-10. Read the editorial policy.