Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 web storage: can different websites overwrite each other’s data on a user’s computer?

I have a few questions regarding the concept of HTML5 storage. I went through the w3c specification, books and tutorials on the same, but still I am a bit unclear about certain concepts:

Assume that I access Website A. Some JavaScript runs in my browser that sets a key value pair, say ('username','deepak'). Then I access Website B which also adds a key,value pair in the localstorage as ('username','mahalingam').

  • How will they both be differentiated?
  • Will Website B override the value set by website A in my localstorage?
  • How can we ensure that a website would not erase all of my localstorage?
like image 307
codingsplash Avatar asked Sep 15 '12 13:09

codingsplash


People also ask

How does the data is stored in HTML5 web storage?

With web storage, web applications can store data locally within the user's browser. Before HTML5, application data had to be stored in cookies, included in every server request. Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance.

What is HTML5 web storage difference types of web storage?

Types of Web StorageLocal storage: Stores data with no expiration date. The data will be available even when the browser/ browsing tab is closed or reopened. Session storage: Stores data for one session. Data persisted will be cleared as soon as the user closes the browser.

Can you access localStorage from another website?

As you may know, LocalStorage is domain based. You can't read or write from localstorage that's on different domain, even if that's subdomain. But there is iframe trick that you can use to store data from domain to it's subdomain.

Is localStorage shared between users?

The localStorage is shared between all windows with the same origin, so if we set the data in one window, the change becomes visible in another one.


1 Answers

Local Storage Privacy

Website A and Website B would have their own local storage. Usually you would have to store certain information in a server database and sync it to the local storage.

I would use the local storage as a cache to get data once and update it at a certain interval depending on when I would want to invalidate the cache. For instance, you could sync with the server when the user A would log out and user B would want to login.

Have a look at the Privacy section in the HTML5 spec for Web Storage.

More information information and resources here: HTML5 Rocks.

Testing

I would suggest the use of a local server setup such as Linux/Mac/Windows, Apache, MySQL, PHP stack (LAMP/MAMP/WAMP) to test on localhost (127.0.0.1).

Most browsers will limit you to 5 MB per domain for every window and tab because of the HTML5 spec recommendation.

I haven't tried this, but you could perhaps have a look at changing the port number of the localhost in Apache's httpd.conf (to do so, find Listen and change the port associated to it) and see if this will do the trick. Basically, you run each test under a different port number to have the whole storage limit for each test.

An alternative would be to create a Chrome extension. You can read more information about this here:

  • Managing HTML5 Offline Storage
  • Manifest files
like image 150
Alerty Avatar answered Nov 15 '22 16:11

Alerty