Please Stop Using Local Storage
rdegges.com
rdegges.com
Essentially, if a website has an XSS your information is compromised no matter what mechanism the site uses to store it.
When it comes to web-apps, XSS is game over. It's the web equivalent of remote code execution.
> One of the annoying things about cookies (the only real alternative to local storage) is that they need to be created by a web server. Boo!
He says that any JS code on the page can access Local Storage but he doesn't mention that Cookies can be accessed by JS as well as Local Storage. And also, Cookies will be sent with each request event if request target is an image or a CSS, when with Local Storage you can decide which data should be sent with each individual request.
He says that Local Storage can store strings only, but he doesn't tell that Cookies is even worse than this - it's JUST ONE string at all.
After that he tells about Cookie-related CSRF attacks prevention which not needed with Local Storage.
Doesn't he contradict himself?
I found a good comparison of all browser storage options on Quora: https://www.quora.com/What-is-the-difference-between-session...
I believe all of the author's stated shortcomings of local storage apply to all browser storage options.
* String Only
* Synchronous
* No Web Worker Support
* Size Limits (smaller for cookies but all have limits)
* Any JavaScript code on the page has access (don't include scripts you don't trust)
Also, keep in mind...
* There is no guarantee the browser will encrypt the content on disk. I believe chrome encrypts cookies, but I'm don't think others do. I don't believe local storage is encrypted at all. Session storage & session cookies should only be in memory. You shouldn't be storing PII in the browser anyway.
* These storage options can't be accessed by other domains as they conform to the same origin policy, but this is an important caveat: The "origin" of the script is the page it is executed in, not where it comes from. So, if you include <script src="http://somehacker.com/superLib.js"></script> it will execute in your origin and can access everything. Protect your users by only including scripts you know are safe. * https://stackoverflow.com/questions/12543978/same-origin-pol... * https://developer.mozilla.org/en-US/docs/Web/Security/Same-o...
In short, do some research and use the right tool for the right job.