Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple authenticate requests from the same session causes state mismatch or undefined session information #154

Closed
2 tasks done
jmaixl opened this issue Feb 21, 2019 · 2 comments
Labels

Comments

@jmaixl
Copy link

jmaixl commented Feb 21, 2019

Describe the bug

The provided passport strategy errors out when multiple authenticate requests are issued from the same session, and the error depends on the order in which these requests are handled.
This is happening before the verify() callback of the strategy.

Steps to reproduce the behaviour:

Invoke authenticate() with 2 requests (A then B) but with the same session (e.g. 2 browser tabs). Proceed as the end-user to authenticate with the identity provider those 2 requests in the following orders:

  1. If we satisfy B first, B authenticates normally, but the first request hits an error:
    did not find expected authorization request details in session, req.session[...] is undefined
    because the req.session[sessionKey] was deleted while satisfying B.
  2. If we satisfy A first, then A hits an error "state mismatch" in client.js because req.session[sessionKey] contains B's state now.

Expected behaviour
Both requests should authenticate normally regardless of their order.

Environment:

  • openid-client version: [latest]
  • node version: [v8.7.0]

Additional context
Could this be fixed by modifying what is persisted in the session? Instead of persisting the state in req.session[sessionKey], persist the state in req.session[sessionKey][state]?

  • the bug is happening on latest openid-client too.
  • i have searched the issues tracker on github for similar issues and couldn't find anything related.
@panva
Copy link
Owner

panva commented Feb 22, 2019

I don't see a way around this honestly, as part of the callback there will be cleanup of the temporary session namespace the strategy uses.

Could this be fixed by modifying what is persisted in the session? Instead of persisting the state in req.session[sessionKey], persist the state in req.session[sessionKey][state]?

Not really, see here https://github.com/panva/node-openid-client/blob/v2.4.5/lib/passport_strategy.js#L129 the cleanup.

I'm gonna close this and label as won't fix since it's just exhibiting well defined behaviours during an edge case, not using a state would pose a way bigger issue. And either way, it just surfaces as an issue with the state, but would be the case with everything that's pulled from the session.

@panva panva closed this as completed Feb 22, 2019
@panva panva added the wontfix label Feb 22, 2019
@jmaixl
Copy link
Author

jmaixl commented Feb 22, 2019

Yes, I noticed the cleanup as part of the callback - that could be changed to cleanup req.session[sessionKey][state]. But I will respect the wontfix if that' still the final decision.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants