Yadis

Identity, trust and the plumbing of the web·on the home of the Yadis discovery protocol since 2005

§03  Security & Privacy

Session Timeout Best Practice: How Long Should a Session Last?

Session Timeout Best Practice: How Long Should a Session Last?

"Mitmach-Sonnenuhr" 01 / Ku0ricino, CC0

Web applications tend to use a defining function or routine called a session to keep a user logged in until:

Fixed or copy-and-paste session timeouts are all too common in web applications, and they cause:

Copying session-lasting configurations from a vendor or another application is extremely risky. Instead:

Your goal in managing session lifetimes is to:

Your Timer Is Running: The Need for Absolute and Idle Session Lifetimes

A session timeout can catch an attacker in what might be called the window of attack opportunities - and the slowness of actual make-a-break access.

Absolute Timeouts Limit User Access

Security guidance recommends schemes where:

With absolute timeouts, if your session becomes exposed:

then it will STAY usable, even if there is no user activity.

Attacker Window

The time between when the attacker starts an exploit and when they can achieve an attack - in this case, when they can examine, interfere with, or exfiltrate application data.

The OWASP Session Management Cheat Sheet advises:

Making You Chase Them Down

On the other hand, very short timeouts:

So in both cases, you need to catch an attacker inside the application, but you also need to respect the user workflow.

The WorkOS blog, describing OWASP advice, recommends:

Explicit Logouts Must Invalidate:

Application's that require explicit logout in browsers cannot control what the browser does, but should still:

Explicit timeout and logout processes invoke the principle known as the "least privilege." This principle limits access:

What Do the Standards Say?

OWASP advises:

NIST's B.6 Session Management guidance includes:

Across the board, credentials should last no longer than:

People sometimes copy other sessions' Expires parameters, aimlessly worrying about security.

For session time limits related to refresh tokens, refresh tokens should be treated as single-use, with each use yielding a refreshed set of refresh tokens. The Calendly Developer Guide - Refresh token rotation guide:

Exploitation Techniques:

Thieving or violating the token can give an attacker access if either idle or absolute timeout is missing or exceedingly long.

Explicit logout remediates attacks that steal:

All: idle timeouts, explicit logouts, and refresh-token rotation complement effective principles in this case: "Limit subject privileges," "Ensure the ability for accountability," and ""

Refresh tokens have a tendency to be ideal for exploitation and are frequently cached to browser storage.

Choosing a Number: Attack Window, Revocation, and Workflow

Understanding attackers and session lengths is important, you also must understand work flows. If a user must unlock a machine or re-authenticate often, it'll:

WorkOS warns:

For highly sensitive environments, hotline checking or similar may make shorter expiration times acceptable.

Crucially, absolute limits are:

The Calendly Developer Guide advises this combination:

Whatever lifetime you choose, it must be shorter than the attacked window, longer than the refresh period, and assured by server-side session invalidation.

Going forward, this knowledge should help you from deciding session lengths without context.