Session Lifecycle and Persistent Login
Follow session credentials through login, replacement, remember-me, and logout to see which old credentials should stop working.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
A browser has a session identifier before login. Mia signs in, leaves, returns using "remember me," and eventually signs out. Which old credentials should still work at each point?
A session is more than a cookie with sensible attributes. The server must decide when an identifier becomes authenticated, when to replace it, and when to stop accepting it.
| Moment | What to inspect |
|---|---|
| Login | A completed identity is attached through the supported login operation |
| Identifier replacement | The old identifier does not inherit the new authenticated session |
| Remember-me restoration | A valid, current server-recognized credential restores the intended identity |
| Logout | The credentials covered by logout are invalidated |
We'll follow that timeline, then distinguish session fixation from a forgeable persistent-login token.
Trace session creation and verification
Identify the session backend. A server-side store, signed client cookie, and encrypted client cookie have different mechanics. Determine how a request resolves to a user, which state establishes completed authentication, how expiry is enforced, and how a revoked credential is rejected. A cookie named session is not a complete design description.
# Unsafe server-side-session teaching outline.
user = authenticate(request, username=body['username'], password=body['password'])
if user:
request.session['user_id'] = user.id
return redirect('/inbox')
The credential comparison may be correct. The issue is the transition from an anonymous session identifier to an authenticated identity without rotation. Calling authenticate checks credentials; it does not necessarily perform the framework's login lifecycle. A custom user_id reader may bypass other framework protections as well.
Inspect how the same bytes are treated across lifecycle events.
Before login. An attacker-known identifier must not become a reusable authenticated credential.
session A -> anonymous fixture state
After login. The supported login operation changes the identity carrier and preserves only allowed state.
session B -> completed user identity
session A -> no authenticated identity
Persistent restore. A long-lived token needs issuer proof or opaque lookup, expiry, and revocation.
random token -> digest lookup -> live state -> permitted session
Review question: Cookie flags, rotation, token integrity, and revocation enforce different guarantees.