Case DDA2BB · Web AppSec · L2 Practitioner
Secure Session Management
Interview questionHow would you design session management for a new web app? What settings would you insist on?
- 01 Answer
- 02 Example
- 03 Trade-offs
What a strong answer covers
Try it out loud first. Then check yourself:
- Server-generated session ID from a CSPRNG with high entropy, opaque and meaningless; never put it in URLs
- Cookie flags: Secure, HttpOnly, SameSite=Lax or Strict, narrow Path, and the __Host- prefix to block subdomain overwrite
- Rotate the ID on login and privilege change to stop session fixation; invalidate server-side on logout and password change
- Idle and absolute timeouts sized to risk; re-authenticate for sensitive actions like changing email or MFA
- Trade-off: stateful sessions revoke instantly; stateless JWTs scale easily but need short expiry plus refresh to revoke
If the interviewer pushes back
- A user reports being logged in on a device they do not recognise. What does your design let them, and you, do about it?