-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Labels
in: webAn issue in web modules (web, webmvc)An issue in web modules (web, webmvc)status: duplicateA duplicate of another issueA duplicate of another issuetype: enhancementA general enhancementA general enhancement
Milestone
Description
Describe the bug
On logout in a Reactive application, the WebSession
is not invalidated.
To Reproduce
- Login with a user.
- Add attributes to the session.
- Logout.
- Login with the same or another user from the same browser.
- Attributes added in step 2 are available in the new session.
See SessionInvalidationTest.java in the sample repo for the reproducer test case.
Reproduced for HTTP Basic in the provided test case and in OAuth2 login/logout in the product code.
Expected behavior
WebSession
is invalidated on logout.
Actual behavior
Only the ID of the session (WebSession#changeSessionId
) and security context attribute is updated.
Workaround
Add a custom ServerLogoutHandler
wrapped in a DelegatingServerLogoutHandler
to join it with the default SecurityContextServerLogoutHandler
:
.logout(logout -> logout
.logoutHandler(new DelegatingServerLogoutHandler(
new SecurityContextServerLogoutHandler(),
(exchange, authentication) -> exchange.getExchange()
.getSession()
.flatMap(WebSession::invalidate)
))
)
Sample
https://github.com/orange-buffalo/spring-security-session-invalidation-reproducer
Metadata
Metadata
Assignees
Labels
in: webAn issue in web modules (web, webmvc)An issue in web modules (web, webmvc)status: duplicateA duplicate of another issueA duplicate of another issuetype: enhancementA general enhancementA general enhancement