Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage in Firefox extension throws "The operation is insecure." exception

I am developong Firefox Add-on that uses localStorage to store user data in website context. It access localStorage via injected content scripts using standard methods:

localStorage.getItem(key);
localStorage.setItem(key, value);

The code that calls localStorege is injected to website via PageMod:

pageMod.PageMod({
    contentScriptFile: [
        self.data.url("app.js")
    ]})

When methods getItem/setItem are called, security exception is thrown:

[Exception... "The operation is insecure." code: "18" nsresult: "0x80530012 (SecurityError)" location: ""]

So far I did not find out the reason why this is happening. I have an suspicion that it may have something to do with old FireFox bug, but probability is low: http://meyerweb.com/eric/thoughts/2012/04/25/firefox-failing-localstorage/

Maybe anyone could suggest an idea what could cause a problem?

Additional info:

  • We are using Addon SDK 1.16
  • Problem occurs since FF 29.0 RC1 (everything works with FF 28)
like image 213
xb1itz Avatar asked Apr 24 '14 12:04

xb1itz


People also ask

Can localStorage throw exception?

localStorage object is enough to throw a security error. Luckily, catching this error is quite easy.

Why is localStorage a security risk for an application?

Local storage shares many of the same characteristics as a cookie, including the same security risks. One of those is susceptibility to cross-site scripting, which steals cookies to let hackers masquerade as a user with their login session for a site.

Why localStorage Removeitem is not working?

The reason you are running into an error is because, test is not available in the scope of code ( and a reference error is thrown, when you try to access a variable that is not defined yet). In your case it lives on localStorage. test because you are attaching it directly to localStorage object.

Does localStorage work in incognito mode?

Local Storage data stored on normal browsing sessions will not be available when you open a browser in private browsing or in Incognito mode. Local Storage data will not get cleared even if you close the browser. Because it's stored on your browser cache in your machine.


1 Answers

We also have an extension and are getting the same error with local storage. This is a bug with 29, as @basarat notes this error should only be thrown for CORS issues. We've tested with Aurora and Nightly with no issues either. We're filing a bug with Mozilla.

like image 84
CleanTheRuck Avatar answered Nov 02 '22 11:11

CleanTheRuck