How do cookies, sessions and tokens differ?
Short answer
The three are not the same kind of thing: a cookie is the browser's channel that stores and auto-sends data, a session is login state on the server, a token (JWT) is a signed, self-contained credential. A cookie can carry a session ID or a token.
3 points to say:
- A cookie is only a channel; sessions usually travel in a cookie, tokens in a header or a cookie.
- Sessions revoke instantly (delete on the server); a JWT verifies without a lookup but is hard to revoke before it expires.
- Login cookie:
HttpOnly; Secure; SameSite=Lax; cookies mean worrying about CSRF, while a token inlocalStorageleaks on XSS.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.