

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Authentication
incomplete
2: Stateless vs. Stateful Authentication
incomplete
3: What Are Sessions?
incomplete
4: What Are Cookies?
incomplete
5: Cookie Security
incomplete
6: Session Lifetime
incomplete
7: Password Resets
incomplete
8: Broken Password Reset Flow
incomplete
9: OAuth 2.0
incomplete
10: SAML and OIDC
incomplete
11: API Keys
incomplete
12: Reauthentication
incomplete
13: Authentication Misconceptions
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Once a user is authenticated, the next question isn't "Who are you?" It's:
How long should I keep trusting you?
...which is answered by session timeouts, expiration, and revocation.
Every session should have a server-enforced expiration, commonly stored in an expires_at column. Without a well-defined lifetime:
The server must enforce the expiration. A client-side expiration timestamp helps the browser know when to discard its copy, but an attacker can always bypass browser behavior.
As you can expect, there's a tradeoff here. Short-lived sessions reduce the time an attacker can reuse a stolen session, but they also force users to reauthenticate more often, which is annoying.
Long-lived sessions are more convenient, but they increase the damage window when they're stolen.
There's no single "correct" duration. The right choice depends on what the user is doing, the device, and the damage a stolen session could cause. Applications often combine two limits:
Different actions carry different levels of risk. For example:
| Action | Risk Level |
|---|---|
| Submitting a lesson on Boot.dev | Low |
| Viewing account settings | Medium |
| Making a payment | High |
| Launching a nuclear missile | Super Critical |
Higher-risk actions should require fresher trust.
Expiration isn't enough. You and your users need to be able to revoke access when you suspect a session may be hijacked. Revoking a session means invalidating it immediately. There are also times when a server should automatically revoke sessions, like when a user logs out. It's not enough to just clear the browser cookie.
This is where stateful sessions shine. A server can revoke a session by invalidating its record. A self-contained stateless token can't be individually revoked. That problem can be mitigated (but not eliminated) by short token lifetimes and refresh tokens that can be revoked.
Bearly Secure clears the browser's session_id cookie when a user logs out, but the server-side session record is still valid. If an attacker saved the session ID before logout, they could keep using it until the session expires!
Update logout so it revokes the current server-side session.
With Bearly Secure still running, run and submit the CLI tests from the project root.