Browser cached /oauth2/default/v1/keys causing CORB authentication error


#1

I have a SPA configured with OIDC implicit flow. The application has a few environments that I have configured with the same client ID, and I have made sure the correct redirect URLs and CORS/origins are configured. The app uses React and I am using @okta/okta-react with the sign-in widget for user authentication. The different environment urls are in the format {app}-develop.{org}.com and {app}-staging.{org}.com.

I am experiencing some stochastic errors when logging in to multiple environments either concurrently or sequentially and shortly apart. For example, if I log into the develop environment first and then the staging environment, I get this error:

Failed to load https://{org}.okta.com/oauth2/default/v1/keys: The 'Access-Control-Allow-Origin' header has a value 'https://{app}-develop.{org}.com' that is not equal to the supplied origin. Origin 'https://{app}-staging.{org}.com' is therefore not allowed access.

The browser is caching the keys response, which includes the Access-Control-Allow-Origin for the develop URL. When I try to login to staging, the browser uses the cached response for keys which leads to the CORB error.

I can bypass this error by:

  1. using an incognito window
  2. clearing the browser cache
  3. checking “disable cache” in the browser dev console

All those options aren’t really acceptable for users to do. How can I bypass this error?


CORS issues when using multiple local apps (localhost:<PORT>) to hit the same dev okta account
#2

Follow up, it seems like “disable cache” does not always work either to bypass this error.


CORS issues when using multiple local apps (localhost:<PORT>) to hit the same dev okta account
#3

Hey @lawrence, sorry for the delayed response. This is a known issue when using the same client ID for apps hosted on different URLs. It’s something that we are scheduled to fix, but I don’t have a firm date.

The workaround in the meantime is to use separate Okta applications (separate client IDs). Not ideal, but it works. I’ll make sure to post an update here when the caching issue is resolved.


#4

Hi @nate.barbettini. Thanks for the response. Creating separate client IDs was one of the first things I did as a workaround, but the /keys response caching still remains. I was going to look through the okta-react source to see if the client ID is being used in the request to get the jwks. My initial inclination is to say that does not happen.


#5

For others experiencing this same problem, I’ve gotten a response from a Developer Support Engineer stating

This is a known feature gap and we have a few other customers facing the same issue. We raised a JIRA OKTA-156155 (Restricting CORS origins for JWKS endpoints causes caching problems with multiple application (across multiple origins)) internally to handle this feature gap. The latest update on the JIRA says that this would be addressed in the Q4 of this year, but we do not have any solid timelines for now.


CORS issues when using multiple local apps (localhost:<PORT>) to hit the same dev okta account
#6

Hi Lawrence, I have the same problem and it causes some difficulties for the future deployment of our solution.
Do you have a release date of the fix please ?

best regards.
Vincent


#7

I am still experiencing this issue, therefore I guess it has not been fixed sofar.