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

一个人想着一个人 提交于 2019-12-08 15:45:42

问题


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?

回答1:


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


来源:https://stackoverflow.com/questions/12437836/html5-web-storage-can-different-websites-overwrite-each-other-s-data-on-a-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!