silverstripe / silverstripe-hybridsessions

Hybrid Cookie / DB Session store for Silverstripe
BSD 3-Clause "New" or "Revised" License
16 stars 21 forks source link

Possible race condition with session results in frequently being kicked out of the CMS #78

Closed kartikpatel95 closed 1 year ago

kartikpatel95 commented 1 year ago

With the upgrade of hybrid session module to 2.5.1 and above I am been kicked out of the CMS as it asks to re-authenticate the user but I am not actually logged out as it re-finds my session a moment later and logs me back in but redirects me out of the admin. This happens consistently, making me downgrade back to 2.4 where the issue is not there.

Can this be looked at why it is happening.

Acceptance criteria

GuySartorelli commented 1 year ago

I am been kicked out of the CMS

How long does it take before you are "kicked out"? And when you say "kicked out", do you mean it is automatically taking you to /Security/login, or is it providing an authentication form within the CMS itself?

it re-finds my session a moment later and logs me back in

Can you please describe that behaviour more clearly? What do you mean by it re-finding your session? How do you know it re-finds it? Do you need to interact with the CMS in some way, or does something happen automatically? What does happen?

redirects me out of the admin

Where does it redirect you to? Does that happen immediately when it "re-finds your session"? Or does something happen in between?

making me downgrade back to 2.4 where the issue is not there

Does this mean the issue is actually present in 2.5.0 as well?

gligorkot commented 1 year ago

@GuySartorelli this looks like it's some sort of race condition, after looking into it these are my findings:

Relevant code within Silverstripe framework:

So what we're seeing is, when we go to the CMS admin, we see our authenticator call RequestAuthenticationHandler's authenticateRequest function and generally when looping through the handlers, the session handler gets invoked and the member gets returned correctly. What we find though, after upgrading hybrid sessions to 2.5.1, sometimes the SessionAuthenticationHandler's authenticateRequest function ends up not finding an $id for the member, so it returns null. This then subsequently shows the re-authenticate within the CMS, but soon after finds the user (somehow) and you end up on the "Log in as a different user" screen.

Only thing I can think of is the new session encryption introduced here maybe takes a bit longer to process resulting in a race condition.

GuySartorelli commented 1 year ago

@gligorkot Thank you for looking into this. Can you please give me an idea of how frequently this happens? It will help both reproducing the issue and prioritising working on it.

gligorkot commented 1 year ago

@GuySartorelli it pretty much happens within minutes of us going into the admin section - doesn't happen on the public pages and browsing the site seems all ok, it only happens in the admin section, but happens often and reproducible all the time

kartikpatel95 commented 1 year ago

@GuySartorelli I was wondering if you guys had any luck with this defect.

GuySartorelli commented 1 year ago

@kartikpatel95 We have been focused on getting everything ready for the CMS 5 beta release - we'd definitely welcome a community contribution but otherwise this will need to wait until we have resource available.

GuySartorelli commented 1 year ago

@kartikpatel95 @gligorkot I've been unable to reproduce this issue - can you both please provide as much information as you can about your setups and how to reproduce this?

Including:

maxime-rainville commented 1 year ago

I'll close this since we can't reproduce it. We can look at reopening if we get more context.