by CiPHPerCoder · 7y ago · 0 comments
This is a common mistake.
Don't ever do opportunistic upgrades. Instead, upgrade all at once and retain "legacy" metadata needed to re-authenticate the user until their password hash is rotated. https://paragonie.com/blog/2016/02/how-safely-store-password...
Beyond that: Bcrypt is great, SHA1 is terrible, and the level of technical detail in this advisory is excellent. The fact that I was even able to critique their 7 years old security decision at all speaks volumes to the transparancy.
Don't make this mistake. Rehash all of them up front.
The details of whether or not users are forced to change their password is irrelevant to the escape route from this trap.
- Set all password hashes to Bcrypt(existing SHA-1 Hash)
- Create a new flag column to track whether the password is upgraded to straight Bcrypt.
- If flag is false, compare stored hash with Bcrypt(SHA-1(user input)). If it matches, log user in and replace stored hash with Bcrypt(user input). Set flag true.
- If flag is true, compare stored hash with Bcrypt(user input)
They'd still have leaked all of the insecure hashes of people who never logged in after the change in 2012 -- and that's still not good enough.
Immediate remediation means never keeping toxic hashes on hand, and never having to say to any subset of your customers "Sorry, but your password has been compromised due to our incompetence".
If you ever come across insecurely hashed passwords in your career, always remediate all of them with a second more secure hashing strategy at once.