Description
Setting setMaxInactiveInterval to 0 or a negative value disables expiry due to inactivity for a Servlet session.
Potential impact
A login left on a shared device or an exposed session ID can remain usable. Sensitive functions may stay accessible without reauthentication.
Remediation
Set a positive idle timeout in seconds. Use shorter timeouts and require reauthentication for high-risk functions. On logout, invalidate the server session and expire its cookie.
Examples
Both methods configure an existing HttpSession.
Before
java
void login(HttpSession session) {
session.setMaxInactiveInterval(-30);
}
After
java
void login(HttpSession session) {
session.setMaxInactiveInterval(900);
}
With 900, the session times out after 15 minutes without a request for that session. Set a separate absolute lifetime if it must expire even while requests continue.