Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage and locking

Since (html5) localStorage and its equivalencies persist in between tabs and windows, I've thought about using it for message passing. The problem is that fetch and store are different operations, and therefore not atomic. I have models that rely on UUID generation, conflict resolutions, and beaconing to do the small subset of what I need to do, but my real question is this:

Since the local storage is a shared memory resource, what are the locking mechanisms available for mutual access?

like image 571
kristopolous Avatar asked Dec 24 '10 22:12

kristopolous


People also ask

Is using localStorage secure?

On the downside, localStorage is potentially vulnerable to cross-site scripting (XSS) attacks. If an attacker can inject malicious JavaScript into a webpage, they can steal an access token in localStorage. Also, unlike cookies, localStorage doesn't provide secure attributes that you can set to block attacks.

How do I secure localStorage?

Encryption and decryption is a ways to save data securely to localStorage. However, in this scenario, you'll need a shared secure key to encrypt and decrypt data. Consider the following scenario: you've encrypted the user's login information and saved it locally.

What is local storage disadvantages?

The downsides to local storage are major. Creating and maintaining a local storage system is expensive. The hardware and software can cost thousands of dollars depending on how much space you need. Upgrading can also be costly.

What is the main difference between localStorage and sessionStorage?

The difference between sessionStorage and localStorage is that localStorage data does not expire, whereas sessionStorage data is cleared when the page session ends. A unique page session gets created once a document is loaded in a browser tab. Page sessions are valid for only one tab at a time.


2 Answers

Benjamin Dumke-von der Ehe recently came up with some (experimental) locking code for localStorage: http://balpha.de/2012/03/javascript-concurrency-and-locking-the-html5-localstorage/

like image 68
Andrew Wilcox Avatar answered Sep 28 '22 06:09

Andrew Wilcox


I think what you really need is Channel Messaging, though as far as I'm aware no-one has implemented it yet. It allows arbitrary client side messaging between scripts.

like image 25
robertc Avatar answered Sep 28 '22 06:09

robertc