I've recently asked a question about blanking the password fields in UX for usability purposes, but It seems all the sites use this approach for security reasons. Why is it insecure to post back the same pass that user has entered?
Good question. Having the benefit of looking at some of the answers, and pondering over this myself, I actually don't see any major security benefits from clearing the password from the partial form returned to the user, but there definitely are some risks worth considering.
From a security architecture point of view (as @Roryalsop already touched on), you usually want passwords flowing only in one direction. From the user to the application, never back. This applies on all layers, and this one-way-system gives benefits from a security point of view. Having an exception to this rule might or might not be a good idea. But that's why your question is interesting. Does this scenario deserve an exception?
Lets look at some attack vectors and see if nulling the password protects against any of those:
- sniffing the traffic - if an attacker is able to intercept communication between the user and server, it can sniff the password sent in the first place by the user. I see no benefit in emptying it on the response
- malware on the server or client side - the same. It can intercept the initial password.
- cached data - this was already mentioned briefly by @SachinKumar but is worth expanding. There's an increased chance that if the server returns the password with the response, it might end up cached somewhere (the server memcached, a proxy server along the path, the client's browser history etc). Client requests are never cached. Server responses are! This is probably the biggest risk I see. Proxies can be probably be eliminated from the equation by using SSL, and if the server uses correct cache-headers and sets the input field correctly, this can also mitigate browser-caching. That said, it's still possible that the value gets cached somewhere, even accidentally and that's probably not desirable.
But then, nulling the password is easy enough, shouldn't damage user-experience too much and keep things cleaner from a security standpoint. I would still suggest you keep doing so.
If you're worried about user-experience, try to follow the advice you were already given on UX - perform extra validation on the client side, just so the user gets early feedback. Don't replace the validation on the server. This is the most important validation ultimately. But for user-feedback, client-side validation can work wonders to improve user experience and you don't have to take even a slight risk of the password being cached (or change your security architecture by making an exception).
Why is it insecure to post back the same pass that user has entered?
Because if you then view source on the posted back page, the password will be visible in plain text. This goes against the principle that passwords should only be one way - i.e. passwords can be input but never output. For example, when storing passwords in database, these should be hashed rather than encrypted to prevent them from being extracted if an attacker manages to view the data. Following this principle everywhere will lead to a more secure system.
In this case it can prevent "shoulder surfing" and it can protect against it being cached by the browser and then later viewed.
It is possible to have a good UI and follow this principle. For example, the system could store the hashed and salted password in the server side session state, and then on the post back the form only shows the other fields. Once this have passed validation, the password from the session state is used rather than the ones that the form would have provided. Of course, care must be taken here to invalidate the session if the user does not continue with the registration process so that this password does not override the one set by the next visitor from that browser. otherwise a session fixation attack may be possible.
2 key points here:
- If you have a mechanism to send the password back to the user, then you give an attacker a way to get that password.
- If you can send the password to the user it means you aren't storing it hashed, but using either clear text or reversible encryption. however as @yoav points out, in thus particular scenario IT won't yet have been encrypted, so this point is irrelevant here.
Both of these have risks.
This is why most websites have password reminder and reset mechanisms, so they don't need to send the password back to you. They may send a one-time password to you as a reset, that you must then change.
Some will send your password in an out of band route, but these are getting rarer as the risks continue to build.
(of course the security of password reset mechanisms is another matter)