Session management in web apps: timeouts and logout

How long should a user stay signed in to a business web application, and when should they be logged out? The short answer: every session needs two limits enforced by the server – an inactivity limit and an overall limit measured from sign-in. Logout must terminate the session on the server, not just delete a cookie in the browser. The session identifier should be replaced after sign-in and after every change in permissions, and users should be able to see their active sessions and end them.

For reference: the US standard NIST SP 800-63B-4 sets, for the medium authentication assurance level (AAL2), an overall limit of no more than 24 hours and an inactivity limit of no more than 1 hour; for the highest level (AAL3), no more than 12 hours and 15 minutes of inactivity (NIST SP 800-63B-4). Below you will find how to translate these numbers into a real client portal or internal system.

Why session management is a business issue, not a technical detail

A session is what keeps a user „inside“ after sign-in. If it lasts too long or cannot be reliably ended, data is also accessible to whoever sits down at a forgotten computer, finds a lost phone or no longer works for the client’s company. If it is too short, people lose unfinished work and look for workarounds.

Decisions about sessions therefore belong in the application specification just like roles or backups. The sign-in method, for example passkeys, determines who signs in. Session management determines how long, and under what conditions, that access remains valid.

Two limits: inactivity and overall session length

NIST distinguishes an overall timeout, which limits the session length from sign-in or the last reauthentication, and an inactivity timeout, which ends a session without user activity. Activity resets the inactivity timeout; successful reauthentication resets both. When either limit expires, the session must be terminated (NIST SP 800-63B-4, section 5.2).

OWASP points out that an inactivity limit alone is not enough: an attacker who steals a session can keep it alive with artificial activity. That is why every session should also have an absolute limit regardless of activity (OWASP Session Management Cheat Sheet).

Application type Inactivity limit Overall limit Basis
Standard low-risk account 15–30 minutes Depends on working time; for a full office day 4–8 hours Common ranges according to OWASP
Portal with personal or financial data No more than 1 hour No more than 24 hours NIST AAL2 (SHOULD recommendation)
Administration with high privileges No more than 15 minutes, for high-value apps even 2–5 minutes No more than 12 hours NIST AAL3, OWASP for high-value applications

The table is a starting point, not a finished configuration. Set the actual numbers according to data sensitivity, device types and how people really use the application, and write the decision down. NIST recommends warning users before the inactivity timeout, for example two minutes in advance, and prompting them to save their work before a fixed limit.

Practical example: an accounting firm’s client portal

Illustrative example: an accounting firm runs a portal where clients upload documents and download reports. The firm’s staff also use an administration area where they change client permissions.

  • Clients: 30 minutes of inactivity, an overall limit of 8 hours, and a warning two minutes before logout with the option to continue.
  • Administration: 15 minutes of inactivity, an overall limit of 12 hours, and reauthentication before changing permissions or exporting data.
  • Password change or access removal: all other sessions of that user end immediately.
  • „My devices“ page: a list of active sessions with the time of last use and a „Log out everywhere“ button.

The result is predictable for both the user and the company: a half-completed form is not lost without warning, and a client’s former employee does not keep access just because a browser was left open at work.

How to implement it in an existing application

  1. Map where sessions are created. Browser, mobile app, API tokens, sign-in with a company account (SSO). Each can have its own validity.
  2. Define limits per role and write them down. NIST requires the inactivity and overall limits to be established and documented.
  3. Enforce limits on the server. For every session the server records the creation time and last activity and rejects requests once a limit is exceeded.
  4. Replace the identifier after sign-in and permission changes. OWASP marks this as mandatory at sign-in and lists password changes, permission changes and switching to an administrator role among other cases; it protects against session fixation attacks.
  5. Terminate logout on the server. After logout the server must not accept the old identifier. OWASP also recommends considering the Clear-Site-Data header to clear cache and local data.
  6. Add a session list and „Log out everywhere“. Use the same mechanism for password changes, account blocking and role removal.
  7. Log session events. According to OWASP, creation, renewal, termination, expiry and permission changes belong in the logs, without the session identifiers themselves.
  8. Test the scenarios. Logout in one window, returning after inactivity, a role change during work and an attempt to reuse an old cookie.

Session cookie: recommended attributes

For session cookies NIST requires transmission over HTTPS only and the narrowest practical scope of hostnames and paths. It recommends the HttpOnly attribute, the __Host- prefix with Path=/, SameSite=Lax or Strict, and content limited to an opaque identifier without personal data. According to NIST, the session identifier does not belong in HTML5 Local Storage, where it is exposed to XSS attacks.

Set-Cookie: __Host-session=<random identifier>; Secure; HttpOnly; SameSite=Lax; Path=/

According to MDN, the __Host- prefix guarantees that the cookie was set over HTTPS, has no Domain attribute and is sent only to the host that set it (MDN Set-Cookie). Cookie expiry is only housekeeping in the browser; NIST states explicitly that it must not be relied upon to enforce limits.

Closing the browser is not logging out

MDN notes that browsers with session restore can restore even cookies without an expiry date after a restart. OWASP adds that window-close events are not reliable. Logout must therefore rely on server-side limits and an explicit button which, according to OWASP, is visible on every page.

Logging out of all devices and revoking access

A „Log out everywhere“ feature means the server knows all of a user’s sessions and can invalidate them at once. With sessions stored in a database or fast storage this is simple. With long-lived signed tokens that the server does not track anywhere, it is impossible without an additional mechanism, so address this requirement at the design stage.

NIST also warns that an access token, for example from OAuth, does not prove the user’s presence and, together with a refresh token, may remain valid long after the session has ended. With SSO sign-in, sessions at the identity provider and in the application are independent, so blocking an account in the central system does not by itself end the session in your application. We also cover this in the article on employee offboarding automation; when systems need to be connected, Webiant can help with API integrations.

Trade-offs to decide deliberately

  • Security versus convenience: shorter limits reduce risk, but with long forms and no warning or autosave they lead to lost work.
  • Concurrent sign-ins: OWASP leaves this as an application design decision. Prohibiting multiple sessions increases control but makes working on both a computer and a phone harder.
  • Tracked sessions versus stateless tokens: server-side tracking enables immediate revocation at the cost of storage and a lookup per request.
  • „Remember me“: NIST does not allow cookies as a substitute for authentication; at AAL2 it permits simplified reauthentication only after the inactivity timeout, while the overall limit has not yet expired.

Common mistakes

  • Logout only deletes the cookie in the browser while the server session stays valid.
  • The limit is set only through cookie expiry or only in JavaScript.
  • The session identifier does not change after sign-in or elevation to administrator.
  • A password change does not end sessions on other devices.
  • The session token is stored in localStorage or contains an email address or role in readable form.
  • The application logs the user out without warning and unfinished data is lost.

Pre-launch checklist

  • Inactivity and overall limits are defined for each role and documented.
  • The server rejects a session once either limit is exceeded.
  • The identifier changes after sign-in, password change and permission change.
  • Logout is available from every page and the old identifier is rejected afterwards.
  • Users can see active sessions and end them; an administrator can end the sessions of a blocked account.
  • The cookie has Secure, HttpOnly, SameSite and, where possible, the __Host- prefix.
  • A pre-expiry warning and autosave protect unfinished work.
  • Session events are logged without sensitive values.

Frequently asked questions

How long should a user stay signed in to a business application?

There is no single number. For a portal with personal or financial data, NIST AAL2 is a sensible starting point: no more than 1 hour of inactivity and no more than 24 hours in total. Choose shorter limits for administration.

Is setting the cookie expiry enough?

No. NIST states that cookie expiry must not be used to enforce limits. The server must check the creation time and last activity.

Should other devices be logged out after a password change?

Yes, it is a sensible default. A password change often follows a suspected compromise, and OWASP lists it among the changes after which the session identifier should be renewed.

What if users complain about frequent logouts?

Add a pre-expiry warning with the option to continue and autosave for forms in progress. Only then consider a longer limit that matches the sensitivity of the data.

Need to improve sign-in in your application?

When developing custom web applications, we design sessions, roles and access revocation together with the other requirements. If you have an existing application and are not sure how it behaves after logout or a password change, contact us and we will agree on a review and proposed changes.

Sources

Choose which cookies to allow. You can change your choice at any time using the footer link or cookie button.

Privacy policy and cookie details