Lion Cipher Lab

Build a server-side session manager: idle and absolute timeouts, a 'your devices' list, and sign-out-everywhere

Why it matters

Every 'Where you're signed in' page, every 'sign out of all devices' button, and every 'your password was changed, please log in again' email sits on top of a session manager like the one you build here. When it is missing or naive, a password change leaves the attacker's stolen cookie working, a leaked database backup hands out live logins, and a session used all day never ends. In this lab you measure each of those failures, fix it, and measure the fix: 3 of 3 old cookies survive a naive password change and 0 of 3 survive the hardened one, 100 of 100 dumped raw tokens work and 0 of 100…

What you'll learn

Steps in this lab

  1. What a session manager is, and where this lab sits
  2. Server-side sessions or stateless JWTs: decide before you build
  3. Set up a workspace
  4. Build sessions.py: hashed tokens, minimal metadata, server-side rules
  5. Save measure.py and measure the timeouts
  6. Measure what a leaked sessions table is worth
  7. Measure who survives a password change and an MFA reset
  8. Measure the devices page, revoke-one, and sign-out-everywhere-else
  9. Measure a per-user session cap: evict oldest vs reject newest
  10. Measure the write savings from throttled last_seen updates
  11. Measure re-authentication for sensitive actions
  12. Run it as a real web app and replay a stolen cookie
  13. Privacy: store the least device data that still lets a user recognize a device
  14. Honest limits, and how a pro does it differently

Open the full interactive lab →