spring-projects / spring-projects/spring-security

Switching users creates user sessions

Open
#13,435 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: web status: feedback-provided type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

When upgrading to Spring Boot 2.7.11 and later we started having sessions even though we have explicitly configured the use of the SecurityContextRepository to be the NullSecurityContextRepository. We traced this to #12834.

From my analysis I can see that for #12504 a SecurityContextRepository was added to the SwitchUserFilter with the default being RequestAttributeSecurityContextRepository. Although this is different than the other filters than use the NullSecurityContextRepository as a default, it is still fine since it is not creating sessions. The other filters are:

  • AbstractAuthenticationProcessingFilter
  • AuthenticationFilter
  • AbstractPreAuthenticatedProcessingFilter
  • RememberMeAuthenticationFilter
  • BasicAuthenticationFilter
  • DigestAuthenticationFilter

In my opinion the change done in #12834 is backwards incompatible change since all of a sudden sessions get created. I think that the default should be the same as the other filters i.e. use NullSecurityContextRepository and if a user wants to use something else they can set the SecurityContextRepository that they want to use.

e.g. We have our own SwitchUserConfigurer and we use:

http.apply(new SwitchUserConfigurer<>())

to apply the switch user. This means that people can get the configured security context repository and set it in their own configurer.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SwitchUserFilter and the custom SwitchUserConfigurer described in the issue, then compare their SecurityContextRepository defaults with the listed authentication filters. Reproduce switching users with NullSecurityContextRepository configured and verify that the default behavior no longer creates sessions while an explicitly configured repository still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.