eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

access denied error thrown when cookies disabled #240

Open bpcrao opened 2 years ago

bpcrao commented 2 years ago

Environment: Chrome browser on MacOS

Reproduce Steps

  1. In incognito window mode of chrome browser
  2. toggle "disable cookies" button
  3. try loading the script , it fails accessing localStorage since the localStorage property exists but access is restricted

the handling in the current code is checking if property exists instead it should gracefully handle it by catching the exception and polyfill it.

Error Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document

ffxsam commented 2 years ago

It appears this happens even if you don't change the cookie settings. I'm wondering if Chrome made localstorage access more strict in a recent update. This is actually breaking our application in production.

This is the culprit: https://github.com/eclipse/paho.mqtt.javascript/blob/f5859463aba9a9b7c19f99ab7c4849a723f8d832/src/paho-mqtt.js#L109

That needs to be wrapped in a try/catch and gracefully handled.