ngxs / store

🚀 NGXS - State Management for Angular
http://ngxs.io
MIT License
3.54k stars 402 forks source link

iOS "Security Error: The operation is insecure" when selecting storage engine #573

Closed VidalQuevedo closed 5 years ago

VidalQuevedo commented 6 years ago
On iOS 11.4.1, Safari throws a `Security Error: The operation is insecure` error when trying to determine whether to use localStorage or sessionStorage as storage engine on engineFactory() method: ![screen shot 2018-09-19 at 4 46 42 pm](https://user-images.githubusercontent.com/2157357/45783952-e1f03980-bc2c-11e8-88d6-09ef70b92010.png) ![screen shot 2018-09-19 at 4 54 37 pm](https://user-images.githubusercontent.com/2157357/45783953-e1f03980-bc2c-11e8-9b70-fe6e62dbf7ee.png) I'm not fully sure what causes this issue, but it may be related assigning localStorage / sessionStorage without checking they are actually available in the environment. Any takes on this issue would be great. I'll keep digging to see what else I can find. Thanks, and thanks for your hard work on this amazing lib! ### Versions "@angular/core": "6.1.0", "@ngxs/storage-plugin": "3.2.0", "@ngxs/store": "3.2.0"
splincode commented 5 years ago

@VidalQuevedo @markwhitfeld 3.3.0 fixed it?

markwhitfeld commented 5 years ago

@splincode no, unfortunately not. Its unrelated. Does anyone know how Safari recommends that you access these?

eranshmil commented 5 years ago

I couldn't reproduce it using:

  1. iOS 11.4 and 12.1 emulators.
  2. NGXS 3.2 and 3.3.1.
  3. AOT enabled/disabled.

Are you using Ionic or just plain angular/cli project? AOT enabled/disabled? Is that an issue only in iOS 11.4? Next time, add some more information in your issue. :)

marcelpotirnac commented 2 years ago

The root cause for this issue are the security settings on a specific browsers (some years ago, it was iOS safari in incognito started to block access to localStorage/session storage). This days, many browsers use this practice, but also users are more informed so they can block all storage access. For example Block all cookies settings from chromium browsers, will block storage access too.

I tried searching for any other issues related to this in the repo, but I couldnt find. Adding the current storage plugin will break the application to load (on the cases mentioned above), unless you create a custom storage engine.

DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.