-
Notifications
You must be signed in to change notification settings - Fork 232
oidc-middleware: session not properly stored before redirect #209
Comments
Thanks @zypA13510 , I'm able to see the two connection sessions that you talk about in your reproduction steps. I'll want to spend some more time with this to make sure that I fully understand the problem/solution, but I'll have to defer that for a bit. |
@robertjd actually I have fixed this for my case already. See zypA13510/oidc-okta/fix-upstream. You can review it and apply it back to the main repo if you would like. (For the sake of easier |
FYI I just fixed an error in the previous fix. It's now working fine for me. Please let me know if you would like me to open a PR or provide more info. |
Hi @zypA13510 - Sorry for the delay. Just to clarify, is the expectation that the session cookie will remain constant regardless of the user's authenticated or unauthenticated state? If so, Or - are you suggesting that no session cookie should be created until the user enters an authenticated state? |
Hi @jmelberg-okta, the issue is not caused by The documentation on express-session specifically stated that:
Also, please see jaredhanson/passport#680 and the bunch of issues linked from there. I believe you will agree with me once you read through all those people's issues. Unfortunately, the maintainer of the repo is not responding. |
And btw,
Here, obviously it is modified:
|
@jmelberg-okta Is there any update on this issue? |
I can confirm this issue is also happening in the |
Internal ref: OKTA-255316 |
…To change - OKTA-255316 Resolves: #209
…To change - OKTA-255316 Resolves: #209
…To change - OKTA-255316 Resolves: #209
Issue description
When visiting an URL protected by
oidcUtil.ensureAuthenticated
, the redirect happened prematurely before the session is properly saved in the session store, resulting in a new session being created at the URL specified inroutes.login.path
. And when the user is authenticated, the callback cannot redirect the user back to the URL protected byoidcUtil.ensureAuthenticated
, because the original session is lost.For more information, refers to mweibel/connect-session-sequelize#39 and mweibel/connect-session-sequelize#54. It seems that
connect-couchdb
,connect-mongo
andconnect-session-sequelize
are all affected by this issue, judging from the issues referencing to mweibel/connect-session-sequelize#20.Possible solution
I have traced the issue to a specific middleware used by
oidc-middleware
, it'sconnect-ensure-login
. And I have created a pull request here jaredhanson/connect-ensure-login#28. But the repo seems to be no longer maintained. I would suggest that you forkconnect-ensure-login
to maintain usability.Steps to reproduce
npm init
, andindex.js
with the following content:npm install
dependencies, and run it in node.jsExpected result
The user is first redirected to http://localhost:3000/login, then to Okta, then after successful authentication, back to http://localhost:3000/authorization-code/callback, and to http://localhost:3000/test
Actual result
The user is first redirected to http://localhost:3000/login, in Chrome Dev Tools, I can see that a new session cookie is set (despite the request to /login carries a cookie already). Then the user is redirected to Okta. After successful authentication, the user is redirected back to http://localhost:3000/authorization-code/callback, and then to http://localhost:3000/
In the SQL database, I can see two sessions being created. The first one is the one from
/test
(first time) response, the session is never authenticated nor updated later, and it carries areturnTo:"/test"
attribute. The second one is from/login
response, the session is later authenticated, but does not carry areturnTo:"/test"
at the time authentication is being made.The text was updated successfully, but these errors were encountered: