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

Bug: DOMException / security in cross-origin private browsing mode situations #21

Open
kyr0 opened this issue Nov 17, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@kyr0
Copy link

kyr0 commented Nov 17, 2021

Hi,

there is an issue with a specific security condition where this hook can potentially break a whole web application, also production deploys, just by using it in the intended way.

If you integrate a web app inside of an <iframe> but this <iframe> is not served from the same domain, we have a typical "vertical" / "whitelabel" / "intranet integration" / "extranet integration" use-case.

This standard use case can potentially break a whole application and render a white-screen in production when the user is visiting that site in private mode. In this condition, browsers like Chrome and Firefox activate specific security rules that cause a DOMException to happen, only if you just try to read window.sessionStorage / window.localStorage in your code:

This is happening here:
https://github.com/tiaanduplessis/react-hook-form-persist/blob/master/src/index.js#L16

And causes:

Bildschirmfoto 2021-11-17 um 15 30 19

...based on production transpiled and minified code from this lib:
react-hook-form-persist.js":function(e,t,n){var r=n("../../node_modules/react/index.js");e.exports=function(e,t,n){var a=t.watch,o=t.setValue,i=void 0===n?{}:n,s=i.storage,l=void 0===s?window.sessionStorage:s,

There are two ways to fix this:

  • you can wrap every use of the hook in try/catch
  • we can do that in the lib and provide a mock storage implementation, backed by a global variable object to persist data (more or less like sessionStorage, just that it wouldn't survive hard reloads, which is probably better than breaking code completely and at least gives a working app in most cases; just needs to be documented well)

I have that in code already and can PR it.

Are you aware of this thing and would you accept a PR?

@tiaanduplessis
Copy link
Owner

Hi @kyr0. Thank you for creating the detailed issue and sorry for the delayed response. I wasn't aware of it and will be very happy to accept a PR that resolves it.

@tiaanduplessis tiaanduplessis added the bug Something isn't working label May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants