SteelReed

Search

Search posts, questions…

SecurityQuestion 10 / 24

Junior

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.

carriesor carriesalso carriesserver looks upserver verifiesCookie: auto-sent channelSession IDJWT tokenAuthorization headerSession storeRAM, Redis, DBSignature, no lookup

3 points to say:

  1. A cookie is only a channel; sessions usually travel in a cookie, tokens in a header or a cookie.
  2. Sessions revoke instantly (delete on the server); a JWT verifies without a lookup but is hard to revoke before it expires.
  3. Login cookie: HttpOnly; Secure; SameSite=Lax; cookies mean worrying about CSRF, while a token in localStorage leaks 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.