Skip to content

Library usage with disabled cookies causes "failed to read 'localStorage' from Window: Access denied" #1087

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

Open
raizemm opened this issue Jun 14, 2021 · 3 comments
Labels
bug For tagging faulty or unexpected behavior.

Comments

@raizemm
Copy link

raizemm commented Jun 14, 2021

We ran into an issue using this library inside our app with one of our users who had disabled cookies for all sites inside chrome settings (chrome://settings/cookies, "Block all cookies" or add a new entry to "Sites that can never use cookies" section), which resulted in the application unable to load throwing following error:

image

What we tried to do is to provide MemoryStorage implementation for users with disabled cookies, therefore unable to access localStorage, but unfortunately even if we provided correct Storage to those users the app still won't load.
I think the issue is that inside OAuthService constructor

typeof window['localStorage'] !== 'undefined'

there is a check for localStorage existence which throws the error mentioned above. There are also some other window['localStorage'] checks inside OAuthService which would probably fail in this situation.

Would you even consider this a valid scenario with the fallback to the MemoryStorage to let the application work?
If yes maybe localStorage usages within the library should be wrapped in try-catch block?

@raizemm raizemm closed this as completed Jun 14, 2021
@raizemm raizemm reopened this Jun 15, 2021
@jeroenheijmans
Copy link
Collaborator

I'm a tad confused: the title mentions "cookies", but the question seems to be about storage causing issues? The latter would make more sense, since this library doesn't do anything with cookies as far as I know. (Though your login server will very likely use cookies for interactive flows, so I don't know if OIDC flows will work at all if you're blocking cookies.)

Could you help us get a reproducible scenario? For example something like:

  1. clone the repo, npm install, run the sample app
  2. <specific settings in chrome to enable/disable>
  3. changes to the sample app, if any at all
  4. ways to click/use the sample app
  5. actual outcome or error + expected result

@jeroenheijmans jeroenheijmans added the question For tagging support requests and general questions. label Jun 15, 2021
@raizemm
Copy link
Author

raizemm commented Jun 15, 2021

Sorry I could've used a better title for the question :)

You can easily reproduce the error I mentioned like that:

  1. Go to chrome settings -> Privacy and security -> Cookies and other site data
  2. Under "Sites that can never use cookies" section add any website or any app that's using the library
  3. Reload the site you just added or just open it in new tab
  4. Inside DevTools try to access window.localStorage
  5. You should receive the exception that the access was denied for this document

I know that this behavior is browser-specific and by disabling cookies the browser does more than just that.

@jeroenheijmans
Copy link
Collaborator

Wow, interesting that disabling cookies also disables localStorage. I can imagine it breaks this library too.

That's likely something the lib could be more robust against. I'm not entirely sure if there's gonna be a community member to do a PR (and also note that merging of PRs has been on hold for some time already, at the time of writing), especially since it's a very edge case, which will likely break on the STS side after you'd make this lib robust against it. (Since the Secure Token Server will also likely need cookies to function...)

@jeroenheijmans jeroenheijmans added bug For tagging faulty or unexpected behavior. and removed question For tagging support requests and general questions. labels Jun 15, 2021
@jeroenheijmans jeroenheijmans changed the title Library usage with disabled cookies Library usage with disabled cookies causes "failed to read 'localStorage' from Window: Access denied" Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For tagging faulty or unexpected behavior.
Projects
None yet
Development

No branches or pull requests

2 participants