147 points · by CiPHPerCoder · 9y ago · 86 comments
This! I'm still seeing code snippets on StackOverflow that use hashing for password storage and queries without prepared statements.
I think at the moment that is still a weak spot of PHP.
Edit: my mistake. I was refering to weak hashes like md5 and sha1 or 'home brew' hashing.
As opposed to...?
But at least, if you want to roll your own password hashing, do it right: use hmac, salting, stretching and a decent hash function - or use bcrypt/scrypt and save yourself a few headaches.
For example, I see a lot of this construction in proprietary code:
$passwordHash = md5(md5($password) . md5($salt));
if ($storedHash == $passwordHash) {
// Authenticated successfully
}
I'm quick to find these offending snippets and migrate our clients to use password_hash() and password_verify(). SELECT * FROM user WHERE username = '$username' AND password_hash = MD5('$password')Using bcrypt/scrypt/Argon2id does.
[1]: https://en.wikipedia.org/wiki/MD5#Preimage_vulnerability
If you think I'm wrong, I will gladly admit so, just tell me what the $password is here:
if (md5(md5($password)) == 'c9876599e5e54aa12962ae1fe7b0f752') ...An attacker doesn't care about your password so much as they care about getting 50-80% of the passwords on the system, the majority of which are going to be "password123" or some other garbage you can find in a dictionary attack. If you use something like Bcrypt or Scrypt then running your dictionary cracker becomes a real ordeal, it will take a long time to grind through those entries and find matches. With MD5 it's a joke, you can do most of the common ones in seconds and the trickier variants within hours.
Hashcat (https://hashcat.net/hashcat/) can and will make short work of your double MD5 nonsense.
Additionally, if I can find a bit of text that hashes the same I don't care what the original password was. I have a key that works.
Another thing you should do is not allow common or short passwords. That includes "password123". That alone will immediately elevate your security.
> Additionally, if I can find a bit of text that hashes the same I don't care what the original password was. I have a key that works
And you clearly don't understand how the collusion vulnerability works. You can't create one with a given hash. You carefully craft two documents that hash to the same hash, which you don't know in advance. Again, you can prove me wrong by doing just that to the hash in the code snippet.
I can't emphasize this enough.
Libsodium was Frank Denis's project, which was spawned by NaCl by cryptographers Dan Bernstein, Tanja Lange, and Peter Schwabe.
The participants who voted on the RFC, for the most part, were involved in the technical discussions over the past two years since I first mentioned the notion of doing so (before the PHP 7.0 release).
Similarly, there were 13 people who contributed to the libsodium-php repository (ext/libsodium in PECL). Every single one of them had to consent to relicensing the extension to easily get merged into PHP, and we all did.
I often joke that I'm the worst C developer in all of infosec, but there's some truth to that when it comes to modifying the PHP core.
My main role in the ext/sodium project was saying, "We should do this," and somehow getting people to listen.
It's identical to what was merged to PHP 7.2 (actually a bit better since some pull requests haven't been merged to php-src yet).
I don't believe re-implementing the wheel like that is a 'modern security practice'. I asked why they did that instead of using robust, well tested and well supported libraries and did not get a satisfactory answer.
While it's not the author's project (I think?) he is still part of the company, and I'd hope such a security-focused organization wouldn't have done something like that.
A lot has changed since you last looked at it, and a lot will change before the v2.0.0 rewrite is complete.
I'm glad to hear things have changed in the code however, and wish you the best with the rewrite.
I don't much care one way or the other about whether it's OK to try to take people down a peg, but I do care very much when people do that and then try to get away with pretending that's not what they're doing.