Authentication and authorization · core
Sessions vs JWT
A server session stores login state on the server and gives the browser only a random session id (easy to revoke), while a JWT is a signed token that carries the claims itself (no lookup needed, but hard to revoke before it expires).
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Session: random id (at least 64 bits of entropy) in an HttpOnly cookie -> server looks it up in a store (Redis, DB). Logout or ban = delete the session. Needs a shared store when you have several instances.
- JWT: header.payload.signature, each part base64url. The payload is readable by anyone; the signature only proves it was not changed. Do not put secrets or personal data in it.
- Verify every JWT: pin the allowed algorithm (reject 'none' and never let the token header choose), check signature, exp, nbf, iss and aud; get keys from a trusted source (JWKS), not from the token header.
- Revocation is the hard part: keep JWT access tokens short-lived (minutes) and use refresh tokens, or keep a denylist keyed by jti. OWASP notes that using JWTs as sessions needs its own invalidation design.
- Where JWTs shine: service-to-service calls, APIs used by many clients, short-lived access tokens from an identity provider (OAuth/OIDC).
- HS256 uses one shared secret (sign and verify); RS256/ES256/EdDSA use a private key to sign and a public key to verify, so many services can verify without being able to sign.
The red pen
Common traps: mistake → fix
Mistake: JWTs are encrypted
Fix: signed JWTs are only encoded; anyone can read the payload.
Mistake: JWTs are always better because they are stateless
Fix: you lose easy logout and revocation; sessions are often simpler for a web app.
Mistake: Decoding a JWT checks it
Fix: decoding is not verifying; always verify the signature and claims.
Easy to hard
Questions interviewers ask, easy to hard
- Sessions vs JWT: how do they work and when do you pick each?
- What is inside a JWT? Is it encrypted?
- How do you log a user out or ban them when you use JWTs?
- What is the 'alg: none' attack? Algorithm confusion?
- HS256 vs RS256: when does each make sense?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.