最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

security - Storing user's password for web application in client-side JavaScript - is this secure? - Stack Overflow

programmeradmin1浏览0评论

TL;DR - Storing user's login password for web app in memory in JS for use in client-side encryption of user's data: yea or nay?


I'm working on a web application where users can store notes in the cloud. Users have a password to login. In addition, users can elect to encrypt notes using a password. The notes are stored encrypted in the cloud, meaning only the user can decrypt them (and notes are lost if their password is lost).

For user convenience it would be better to use the same password for account login and for note encryption, and, upon login, to store that password in memory in a JS variable so they don't have to re-enter their password every time the application needs to encrypt or decrypt anything (for instance if they update a note).

Is this insecure? Yes, an attacker with access to the user's machine could do a memory dump, or insert breakpoints into (uglified) JS, etc., and obtain the password. But an attacker with access to the user's machine could do this anyway: in order to log in at all there is necessarily a point where the user's password is accessible in plain text in my application's JS.

So it seems okay to me - no more insecure than not storing it. Thoughts?

TL;DR - Storing user's login password for web app in memory in JS for use in client-side encryption of user's data: yea or nay?


I'm working on a web application where users can store notes in the cloud. Users have a password to login. In addition, users can elect to encrypt notes using a password. The notes are stored encrypted in the cloud, meaning only the user can decrypt them (and notes are lost if their password is lost).

For user convenience it would be better to use the same password for account login and for note encryption, and, upon login, to store that password in memory in a JS variable so they don't have to re-enter their password every time the application needs to encrypt or decrypt anything (for instance if they update a note).

Is this insecure? Yes, an attacker with access to the user's machine could do a memory dump, or insert breakpoints into (uglified) JS, etc., and obtain the password. But an attacker with access to the user's machine could do this anyway: in order to log in at all there is necessarily a point where the user's password is accessible in plain text in my application's JS.

So it seems okay to me - no more insecure than not storing it. Thoughts?

Share Improve this question asked Jan 4, 2015 at 19:29 tobektobek 4,5493 gold badges36 silver badges42 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Yes, the JavaScript variable will be protected by the Same Origin Policy preventing other domains from accessing this data.

Consider storing a salted hash of the password as a JavaScript variable and then using this hash to encrypt and decrypt data from the cloud. This will protect against a local attacker from querying local variables on somebody else's puter in order to get the password (say they've left their screen unlocked while they grab a coffee). This is a slightly higher risk as an attack which involves stealing the session (which is just as easy to do on an unattended puter) as the password may have been reused on other sites. You don't want your site to be the weak point of an attack gaining access to another user's Gmail, bank account, Facebook, Twitter, etc.

Also consider key stretching in order to make your encryption key "strong enough". As the encryption key is the password (called Password Based Encryption), this needs to derive a key of at least 128 bits of entropy, which is more than your average user's password contains.

Other things to consider in your design:

  • Use TLS to secure all munication over HTTPS.
  • For any session cookies set the Secure Flag and HTTP Only Flag if possible.
  • Use HSTS to ensure future connections from repeat users are HTTPS only.

It is only secure if you use SSL/TLS, because otherwise an network-based attacker may use a man-in-the-middle attack to change the client side JavaScript code in a way that sends the password directly to the attacker including all notes.

If you have that and can effectively prevent the attacker from adding more JavaScript (e.g. through XSS), you should be fine.

Well if only the user can access their own passwords, then it should be fine. But if the cloud is not secured (as you said it is client side) I don't think it would be best. You should use a server side password system instead. I am a full time white hat hacker and anything client side can be easily stolen. If all you are storing are notes and not credit card info, it should be fine.

发布评论

评论列表(0)

  1. 暂无评论