0

I'm attempting to build a browser-based HTML5 application that has the ability to store data locally on a PC (not mobile device) when offline. This data is sensitive and must be secure.

Of course the trick is trying to find a way to be able to access the secure data with Javascript.

I've ruled out browser local storage since its not secure. Could this be accomplished with a local database? If so, where could the DB credentials be stored? Javascript obviously doesn't seem like a good option to store them since its user-readable.

  • 3
    Everything stored at the client may be eventually reverse-engineered, given enough time and dev resources. – Deer Hunter Jul 23 '14 at 9:42
  • You could encrypt it before putting the data into Local Storage. But this sounds like it might be a better case for a normal desktop application, not a web application. – GrandmasterB Jul 23 '14 at 15:50
  • @GrandmasterB yeah its looking that way unfortunately. If i encrypted it before putting it on local storage wouldn't I have to store that key in the javascript anyway? – turbo2oh Jul 23 '14 at 16:11
  • 2
    Yes, or you can pull it off the server as needed. But doing the latter wouldn't help when offline. That's why I recommended a desktop application instead - it'd be a lot more flexible. There are technologies like node-webkit that let you build desktop applications using HTML/JavaScript if you feel you need to stick with that. – GrandmasterB Jul 23 '14 at 16:25
0

Unfortunately, there is no way to do cryptography securely in JavaScript. To summarize key points of the link:

  1. JavaScript has no secure random number generator and no secure key store, meaning it cannot securely generate or store encryption keys.
  2. There is no way to guarantee the browser itself is not compromised.
  3. Without SSL/TLS, there is no way to guarantee the data or code loaded by the browser was that provided by the server.

You can encrypt data on the server then send the data to the client over SSL/TLS. However, once the data is there, you need something to decrypt it, which requires storing the key. Unfortunately, there is no way to securely store the key. Neither local storage nor browser specific systems, e.g. chrome.storage, are encrypted.

There are other options, including ActiveX controls, Java applets, Adobe AIR or Adobe Flash apps. Unfortunately, all of these come either their own security issues or are platform specific. You could write browser plug-ins but these are also browser and sometimes platform specific.

This data is sensitive and must be secure

How secure is it? Convenience or functionality usually trumps security so you will likely have to consider the trade offs, such as:

  1. Can you store some of the data and not the more secure parts? For example, if you are storing customer contact details, cache data that is not Personally Identifiable Information (PII, such as US social security numbers).
  2. Can you require a certain browser or platform? For example, if most of your customers use Windows, consider an ActiveX control or a ClickOnce desktop application. If they use Windows 8+, can you create an app on the Windows app store (as much as this suggestion may make some shudder)?
  3. Does the data change frequently, so the impact of a compromise is small?

Also remember that secure storage is not the only thing to consider. Even if you solve this issue, there is no point storing data securely if it is not delivered over SSL/TLS (so it can be viewed or tampered with in transit) or if you use weak or poor authentication (e.g. unencrypted and unhashed authentication cookie). Similarly, given physical access to the storage medium, there is no way to protect the data from a determined, patient attacker even if it is encrypted.

0

Maybe store data in the cookies encrypted? Or use a 1x1 pixel flash app that talks with the javascript to do things javascript can't do, even talking to an Flash AIR app on the desktop using "LocalConnection" possibly, to give more access to the desktop.

  • 1
    Hm interesting, I had considered an Adobe AIR app instead but wanted to stay in my current skills wheelhouse if possible. – turbo2oh Jul 23 '14 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.