M. Kodirov

STAGE 05 / LESSON 02

Sessions, cookies and JWTs

Sessions and tokens can carry login state, but they have different operational trade-offs.

THE IDEA

Understand it.

A common session design stores session data on the server and sends the browser an opaque session identifier in a cookie. Set appropriate Secure, HttpOnly and SameSite attributes and protect state-changing requests from CSRF as needed.

A JWT is a compact token format. A signed JWT is not automatically encrypted, and its claims must be verified, including signature, issuer, audience and expiration as appropriate. Revocation and storage choices need explicit design.

SEE IT IN CONTEXT

A session-based request

Browser → sends session cookie → server
Server  → looks up session → identifies user
Server  → checks access to requested resource

HttpOnly limits JavaScript access to a cookie; it does not by itself eliminate CSRF or all consequences of XSS.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

GitHub

Documentation checked November 2026

A browser session cookie

GitHub's cookie documentation identifies user_session as a cookie used to log users in.

  1. Browser
  2. Session cookie
  3. GitHub session

What to learn: A cookie can carry a session identifier between requests. The cookie list does not disclose its value or all server-side session details.

Read the source: GitHub cookies

Google

Documentation checked November 2026

A signed identity token

Google's OpenID Connect documentation describes ID tokens as signed JWTs containing identity claims.

  1. User signs in
  2. Google ID token
  3. Application verifies token

What to learn: A JWT is a token format; an application must verify the token and its claims before relying on identity information.

Read the source: Google OpenID Connect

TRY IT YOURSELF

Practice.

Can a signed JWT safely contain a password just because the signature is valid?

Show one possible answer

No. Signing protects integrity, not confidentiality. Do not put passwords or other secrets into token claims.

GO DEEPER

Official references.