Do not wipe out current session when calling findSession with other session IDs #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The contract of
o.a.c.Manager.findSession
is to just return the active session that matches the passed in session ID and does not specify any side-effects with the current session. In the current implementation if you ask for a session that's not the current session it changes thecurrentSession
ThreadLocal which will then cause the current session to not be persisted inafterRequest
.We ran into this problem with Spring Security's session fixation prevention:
Manager.findSession
with the original requested session IDcurrentSession
ThreadLocal causing the current session to not be persistedIf I understand the reasoning behind the implementation, you were trying to make sure the session requested gets persisted in case the caller mutates the returned session. But this leads to the existing, valid, current session not getting persisted. To make sure both the current session and any sessions asked for by
findSession
get persisted there needs to be a mechanism to track all sessions returned byfindSession
that are not the currentSession and make sure those are persisted after the request. However, that's complicated by the fact that multiple concurrent threads could have called findSession for the same session ID. I feel like the implementation should at least honor the currentSession without wiping it out on calls tofindSession
. Best case you've asked for the currentSession, which just returns that existing object, worst case you're asking for other sessions and even the current implementation can't guarantee that the session object returned will get persisted, just the last one asked for.