Javascript – How secure is localstorage

javascriptSecurity

The question says it all really. I want to provide a service but I do not want to store any of the data myself in a database. With all the recent news of hacking etc it seems to me that it is nicer that clients have complete control over their data.

The problem is that the data stored is potentially sensitive. What I was going to do was… when a client visits the website there would be a question asking 'are you on a personal computer or a public computer'. If they are on a public computer the site would refuse access.

If they were on a personal computer it would then prompt them to set a password. All their data would then be encrypted with this password. Now obviously this is not too secure. The encryption method would be in JavaScript and their password in plain text so I assume it would be possible for a savvy user to locate the password in the localStorage and access the data.

I feel though that this isn't too much of a problem. If you are using a personal computer the chances of this happening are remote as… someone else would need access to their specific user account on the computer, someone else would need to know about the site… someone else would need to understand localStorage and how to access it. The sensitive data isn't any that will compromise their identity or much else. It just records something most people wouldn't like publicly published.

So really the question is, is localStorage secure enough?

Additional question.. how difficult is to wipe your localStorage? I wouldn't want users to
accidentally wipe their data.

Finally – is it even worth encrypting / decrypting their data as if you have the password you can access the site..

Best Answer

How about just not storing the password at all, not even in local storage? You can use a key derivation function to get a key from the password. With a salt and a reasonable number of iterations this should be decently secure.