spring-projects / spring-projects/spring-security
DSL builder constructs inconsistent state with custom RememberMeServices
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Based on the recommendation in #3147, I attempted to implement session extension (not really remember-me) by subclassing NullRememberMeServices, overriding loginSuccess to set a long timeout, and adding the following to my DSL configuration block:
.and()
.rememberMe().rememberMeServices(new LongSessionRememberMeServices())
Logging out promptly broke. On debugging, it appears that a new null logout handler is being registered with the LogoutFilter, and then when the filter iterates over the handlers it throws an NPE. This doesn't happen with services that extend AbstractRememberMeServices because there is magic logic that treats RememberMeServices & LogoutHandler specially inside RememberMeConfigurer#getRememberMeServices(H,String). Then in RememberMeConfigurer#init(H):234, the logoutHandler is registered without a defensive null check.
The upshot is that registering a RememberMeServices that does not also implement LogoutFilter will cause a distant NPE whenever logout is attempted. Line 233 should read:
if (logoutConfigurer != null && loginHandler != null) {
Manually skipping the then block in the debugger produced the expected correct behavior.
(I'd submit a PR, but I don't know where the appropriate test coverage for this case should go.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in RememberMeConfigurer#init(H) around line 234 and trace how the custom RememberMeServices is registered with LogoutFilter. Reproduce logout with a service that does not also implement LogoutHandler, then add regression coverage for the null-handler case and verify logout completes without an NPE.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100