okta-react icon indicating copy to clipboard operation
okta-react copied to clipboard

@okta/okta-react Auth redirect for multiple open pages/tabs in a domain race condition

Open hillc5 opened this issue 8 years ago • 23 comments

I'm submitting this issue for the package(s):

  • [ ] jwt-verifier
  • [ ] okta-angular
  • [ ] oidc-middleware
  • [x] okta-react
  • [ ] okta-react-native
  • [ ] okta-vue

I'm submitting a:

  • [ ] Bug report
  • [x] Feature request
  • [ ] Other (Describe below)

Current behavior

With multiple tabs open to protected routes on the same domain, issuing localStorage.clear() causes issues when those tabs redirect at the same time, either redirecting to / or displaying either a AuthSdkError: Unable to retrieve OAuth redirect params cookie or AuthSdkError: OAuth flow response state doesn't match request state.

This is due to the shared localStorage by domain, and the fact that the secureRouterReferrerPath used in ImplicitCallback is a single key in localStorage as well.

Thus one page will overwrite that value, or remove it altogether at some point in the redirect/auth cycle.

Expected behavior

It would be nice to come up with a way to store the originating referrer keyed off of some unique identifier (perhaps even full pathname) in localStorage so that there would be no chance of collision/race-conditions when multiple tabs in the same domain are going through the auth-redirect cycle.

Minimal reproduction of the problem with instructions

Two protected components that check isAuthenticated, and trigger a login or redirect within the same render cycle.

issuing localStorage.clear() should produce the concurrent redirects/auth cycles

Environment

  • Package Version: @okta/okta-reactv1.1.0
  • Browser: Chrome Version 69.0.3497.100 (Official Build) (64-bit)
  • OS: MacOS High Sierra 10.13.6 (17G65)
  • Node version (node -v): 8.11.3
  • Other:

hillc5 avatar Oct 03 '18 19:10 hillc5

~~Internal ref: OKTA-282373~~ Fixed

aarongranick-okta avatar Mar 06 '20 08:03 aarongranick-okta

@aarongranick-okta I am having this issue. Does Okta have any solution?

"@okta/okta-react": "^1.2.3", "react": "16.9.0",
"react-dom": "16.9.0", "react-redux": "7.1.0", "react-router": "5.0.1", "react-router-dom": "5.0.1",

khainx-developer avatar May 08 '20 02:05 khainx-developer

@khainx127 - While we look into a longer-term solution, have you tried setting the tokenManager to use sessionStorage? That would keep the tokens to be per-tab (downside: your authentication would only be valid on the tab)

See tokenManager config option here: https://github.com/okta/okta-oidc-js/tree/master/packages/okta-react#security

swiftone avatar May 08 '20 18:05 swiftone

@swiftone Yes I tried and I will test. Currently, I have some steps to reproduce on Chrome: Tab 1: open http://localhost:3000/ Tab 2: open http://localhost:3000/admin Tab 1: logout Tab 2: logout Tab 1: login and at http://localhost:3000/implicit/callback, I have error AuthSdkError: OAuth flow response state doesn't match request state Tab 2: login and at http://localhost:3000/implicit/callback, I have error AuthSdkError: AuthSdkError: Unable to retrieve OAuth redirect params cookie

khainx-developer avatar May 10 '20 03:05 khainx-developer

i'm also having the same issues. any solutions pleae?

kandasj avatar May 26 '20 11:05 kandasj

@khainx127 @kandasj - Two bits of data for you:

  1. okta-react 3.x should help address the problem, as it prevents two components from both kicking off a login cycle.
  2. ...that said, okta-react 3.x defaults to using PKCE, and we're chasing a bug were that may make overlapping login efforts run into similar problems.

I recommend using okta-react 3.x without PKCE (using the Implicit Flow, which you are currently using if you are using okta-react 1.x) to see if that fixes your problems. If so, I then suggest trying to upgrade to using PKCE and see if the problems remain fixed (if not, we're actively working on the PKCE-related issues).

swiftone avatar May 29 '20 19:05 swiftone

We have the same issue happening, any updates on this one?

DavidLozzi avatar Aug 31 '20 16:08 DavidLozzi

@DavidLozzi We are working on a fix this issue, you can track the progress in https://github.com/okta/okta-oidc-js/pull/884

shuowu avatar Aug 31 '20 17:08 shuowu

@shuowu i see it was merged, yay! What's the typical turn around time for a release?

DavidLozzi avatar Sep 02 '20 13:09 DavidLozzi

@DavidLozzi Version 3.0.6 is available on npm now.

shuowu avatar Sep 02 '20 14:09 shuowu

@shuowu @swiftone currently we can't recreate this issue in our oktapreview pre-prod environment. Our security team is comparing the two environments, anything we should be looking into why? We want to recreate the issue in pre-prod prior to deploying this release.

DavidLozzi avatar Sep 02 '20 19:09 DavidLozzi

@DavidLozzi The fix in 3.0.6 changed to use sessionStorage instead of localStorage for referrerRoute data (redirect user back to previous route before login). As sessionStorage only keep the data tab specific, I don't see any potential issue with that.

shuowu avatar Sep 02 '20 19:09 shuowu

@shuowu i guess the question is why would this work in oktapreview and not in prod? Is there anything environmentally that you're aware of on how oktapreview works, that okta prod isn't doing? Or visa versa? We can't recreate the tabbing problem in oktapreview and trying to so we can know if this fix will help.

DavidLozzi avatar Sep 02 '20 19:09 DavidLozzi

@DavidLozzi I am not aware of any environmental difference may cause this issue. @swiftone Any thoughts?

shuowu avatar Sep 02 '20 19:09 shuowu

@DavidLozzi It may be related to the version of the signin widget. https://github.com/okta/okta-signin-widget/pull/1390 brought in the latest version of okta-auth-js which should now use sessionStorage by default. This change was merged 9 days ago so probably only exists in the latest version of the signin-widget.

aarongranick-okta avatar Sep 02 '20 20:09 aarongranick-okta

We have the same issue happening with the @okta/okta-angular package. @shuowu any chance of getting this same fix applied there?

bryan1495 avatar Sep 03 '20 09:09 bryan1495

@bryan1495 @okta/okta-angular has switched to use sessionStorage since v2.0.0. Can you try to upgrade to the latest version and see if the issue still exists?

shuowu avatar Sep 03 '20 14:09 shuowu

@shuowu I'm on @okta/[email protected], and that's pulling in @okta/[email protected], which I believe are the latest?

bryan1495 avatar Sep 03 '20 16:09 bryan1495

@bryan1495 you are right, the issue looks like still exist with that storage change for referrerRoute.

Internal Ref: OKTA-327716

shuowu avatar Sep 03 '20 20:09 shuowu

@Shyamsj I transferred your issue to a private repo, and unfortunately, I cannot transfer it to public one now.

Please, see this issue which seems similar to the one you reported. This is the right repo to ask questions about the Angular package.

laura-rodriguez avatar Sep 08 '20 16:09 laura-rodriguez