Skip to content

Session is not invalidated on logout #8971

@orange-buffalo

Description

@orange-buffalo

Describe the bug
On logout in a Reactive application, the WebSession is not invalidated.

To Reproduce

  1. Login with a user.
  2. Add attributes to the session.
  3. Logout.
  4. Login with the same or another user from the same browser.
  5. 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

No one assigned

    Labels

    in: webAn issue in web modules (web, webmvc)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions