- user submits login credentials, e.g email and password
- server verifies the credentials against the DB
- server creates a temporary user session
- server issues a cookie with a session ID
- user sends the cookie with each request
- server validates the cookie against the session store and grants access
- when user logs out, server destorys the session and clear the cookie
- every user session is stored server-side(statefull)
- memory e.g file system
- cache e.g Redis; or
- DB e.g Mongo
- user is identified by a session ID
- opaque; meaning
- no 3rd party can extract data out
- only issuing server can map the session ID back to the secure data.
- stored in a cookie
- signed with a secret
- opaque; meaning
Cookieheader is just likeAuthorizationorContent-Type- used in session management, tracking
- consists of name, values and optional attributes / flags
Usage
Set-Cookieby server, and appended withCookieby browser
DomainandPath; can only be used on a given site and routeExpiration; can only be used until expiry- when omitted, becomes a session cookie
- gets deleted when browser is closed
HttpOnly; cannot be read with JS on the client-sideSecure; can only be sent encrypted HTTPS channel,SameSite; can only be sent from the same domain, i.e no CORS sharing