Session fixation and incomplete logout in micronaut-security-session
Description
Packages and affected stable versions:
io.micronaut:micronaut-security-session(legacy coordinates):>= 1.0.0, <= 1.4.0. The first affected stable version is 1.0.0.io.micronaut.security:micronaut-security-session:>= 2.0.0, <= 3.11.1;>= 4.0.0, <= 4.18.0;>= 5.0.0, <= 5.4.0; and= 5.5.0.
Patched versions: Under io.micronaut.security, upgrade to 3.11.2, 4.18.1, 5.4.1, or 5.5.1 for the corresponding release line. The legacy io.micronaut coordinates have no patched release; migrate to io.micronaut.security:micronaut-security-session and use a patched version.
Severity: Medium CVSS v3.1: 6.8 — CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N CWE: CWE-384 (Session Fixation), CWE-613 (Insufficient Session Expiration)
Summary
When Micronaut Security is configured with micronaut.security.authentication: session, a successful login can reuse a session that already exists on the request, and logout removes only the authentication attribute instead of invalidating the session. An attacker who can cause a victim's browser to use a known session identifier before login may have that identifier authenticated as the victim. After logout, the identifier and other session attributes remain valid.
Details
SessionLoginHandler stores the authentication in the session already associated with the request, creating a session only when none exists:
Session session = SessionForRequest.find(request)
.orElseGet(() -> SessionForRequest.create(sessionStore, request));
sessionPopulators.forEach(p -> p.populateSession(request, authentication, session));SessionLogoutHandler removes only the authentication attribute; it does not delete the session from SessionStore or expire the session cookie:
Optional<Session> existing = request.getAttributes()
.get(HttpSessionFilter.SESSION_ATTRIBUTE, Session.class);
existing.ifPresent(session -> session.remove(SecurityFilter.AUTHENTICATION));The session identifier therefore survives login and logout. Other session attributes, including a CSRF token written by CsrfSessionPopulator when micronaut-security-csrf is present, also survive logout.
Only applications using session-based authentication are affected. Applications using bearer, cookie (JWT), or idtoken authentication modes do not use these handlers.
Impact
- Session fixation: If an attacker can set or otherwise plant the application's
SESSIONcookie in a victim's browser, the victim may be authenticated under an identifier known to the attacker. The attacker can then present that identifier to act as the victim. - Session reuse after logout: A captured session identifier continues to refer to the session after logout. Application code that treats logout as a security boundary may leave other per-session state, such as a CSRF token, available.
Proof of concept
- Configure
micronaut.security.authentication: sessionwith anAuthenticationProvider. - Obtain a session identifier, for example by requesting a page that creates a session.
- Cause the victim's browser to send that identifier as the application's
SESSIONcookie. - The victim logs in. The existing session is populated with the victim's authentication instead of being replaced.
- The attacker sends a request with the same cookie to a secured endpoint and is served as the victim.
- The victim logs out. Because the session is not invalidated, its identifier and other session attributes remain in the store.
The former SessionReUseSpec test documented the vulnerable behavior by reusing the same session through login, logout, and login.
Patches
The fix creates a fresh session after successful authentication, removes the prior session from the SessionStore, and deletes the session and expires its cookie on logout. The first patched stable releases are 3.11.2, 4.18.1, 5.4.1, and 5.5.1 on their respective release lines.
The artifact's stable releases through 1.4.0 used io.micronaut:micronaut-security-session. Starting with stable 2.0.0, it uses io.micronaut.security:micronaut-security-session. No patched release was published under the legacy coordinates.
Workarounds
If an upgrade is not immediately possible, provide custom login and logout handlers that rotate the session identifier after successful authentication and invalidate the server-side session on logout. Reducing micronaut.session.max-inactive-interval does not prevent session fixation.
References
- CWE-384: cwe.mitre.org/
data/ definitions/ 384.html - CWE-613: cwe.mitre.org/
data/ definitions/ 613.html - OWASP Session Management Cheat Sheet: cheatsheetseries.owasp.org/
cheatsheets/ Session_Management_Cheat_Sheet.html
Credits
Found during an internal code review of the Micronaut Security modules.
Fix commits
- Micronaut Security 5.5.x (5.5.1): github.com/
micronaut-projects/ micronaut-security/ commit/ 904abf9c7cfc22c4f22c29fa3cf185bb23a2b088 - Micronaut Security 5.4.x (5.4.1): github.com/
micronaut-projects/ micronaut-security/ commit/ c2454232ccd0095830fc4ba166c79a4ab950f64d - Micronaut Security 4.x (4.18.1): github.com/
micronaut-projects/ micronaut-security/ commit/ f7cd4d286cbb71b379dacb65f4c378a010a5bbba - Micronaut Security 3.x (3.11.2): github.com/
micronaut-projects/ micronaut-security/ commit/ d7f3fceb9596c5c5fe8d44775aec6db62472b9c0
Affected versions
- io.micronaut:micronaut-security-sessionFrom 1.0.0 · through 1.4.0
- io.micronaut.security:micronaut-security-sessionFrom 2.0.0 · through 3.11.1
- io.micronaut.security:micronaut-security-sessionFrom 4.0.0 · through 4.18.0
- io.micronaut.security:micronaut-security-sessionFrom 5.0.0 · through 5.4.0
- io.micronaut.security:micronaut-security-session5.5.0