Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated
Session timeout is a mechanism that logs a user out automatically if there is no activity for a set time. It shortens the time during which someone else can use a screen left open when its user walked away. The idea is to give the logged-in state a lifespan, so it does not stay valid forever.
How does session timeout work?
Picture a meeting room that locks itself. If nobody uses it for a set time, the lock closes. A logged-in state is given a valid time in the same way.
OWASP's session management cheat sheet explains two kinds of expiry. One is the idle limit, which closes a session a set time after activity stops. The other is the absolute limit, which caps the whole lifespan even if activity continues. NIST SP 800-63B-4 also gives two kinds, an overall limit and an inactivity limit.
OWASP asks that these limits be enforced on the server side. As a guide, idle limits run from 2 to 5 minutes for high-value services and 15 to 30 minutes for low-risk ones. The absolute limit depends on the use. For a business screen used all day, 4 to 8 hours is given as an example. The idea of the session itself is covered in session management flaws. If you want help setting the limits for your own member site, contact us.
Why does session timeout matter?
If the mark that shows a logged-in state is stolen, and there is no expiry, that mark stays usable forever. OWASP also lists regenerating the session ID from time to time. The old ID is invalidated after a short grace period, to limit how long a stolen ID is of use.
If you set the limit too short, users must log in again and again. Decide it by balancing the weight of what you protect against ease of use. For example, you could make invoices and personal information screens short and mostly viewing screens longer. When you review, check these points.
- Expire the session on the server automatically when inactivity continues.
- Cap the whole lifespan even if activity continues.
- Make a logout action invalidate the server-side session too.
- Regenerate the session ID after login.
OWASP says a logout action should revoke together all the IDs issued during the same login, including regenerated IDs and old IDs in a grace period. Avoid a design in which state remains on the server after the button is pressed.
Related terms
- Session: the series of usage from login to the end
- Cookie: a small record saved in the browser
- Session hijacking: an attack that steals a logged-in state to impersonate the person
- Session fixation: an attack that makes someone use a fixed ID, leading to takeover
Frequently asked questions
How long should the idle time be?
It depends on how serious the protected thing is. OWASP gives 2 to 5 minutes for high-value services and 15 to 30 minutes for low-risk ones as examples. Decide the actual value by balancing the weight of the information on screen against ease of use.
What happens when the logout button is pressed?
OWASP says a logout action should at least invalidate the session on the server side. Just closing the screen can leave state on the server. Provide the button, and build it so pressing it revokes the session.
Next step
For a review of how logged-in state is managed as a whole, start with session management flaws. The free URL check shows only what is visible from outside your member site, and for help deciding the limits, contact us.
Frequently asked questions
How long should the idle time be?
It depends on how serious the protected thing is. OWASP gives 2 to 5 minutes for high-value services and 15 to 30 minutes for low-risk ones as examples. Decide the actual value by balancing the weight of the information on screen against ease of use.
What happens when the logout button is pressed?
OWASP says a logout action should at least invalidate the session on the server side. Just closing the screen can leave state on the server. Provide the button, and build it so pressing it revokes the session.