From admin/model/user/user.php:
public function editPassword($user_id, $password) {
$this->db->query("UPDATE `" . DB_PREFIX . "user` SET salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "', code = '' WHERE user_id = '" . (int)$user_id . "'");
}
There are several things wrong with this line of code.
rand() is not an appropriate way to generate salts. According to PHP.net, rand() is not cryptographically secure way to generate random values. Salts have to be globally unique and using a good CSPRNG is the best way to achieve this.
- Three iterations of
SHA1 is most definitely not a good password hashing algorithm. This will fall very quickly to GPU-wielding attackers.
Recommendations:
- Please read How to securely hash passwords? for password hashing best practices.
- Use
bcrypt. In PHP 5.5 and above, this can easily be done using password_hash(). For older PHP versions, there is the excellent phpass library.
admin/model/user/user.php is not the only part of the code that suffers from this vulnerability. I noticed the same problem in system/library/customer.php.
Does opencart have a way to be contacted privately for security issues? I would prefer not to open an issue publicly in the future especially for more high-risk bugs.
From
admin/model/user/user.php:There are several things wrong with this line of code.
rand()is not an appropriate way to generate salts. According to PHP.net,rand()is not cryptographically secure way to generate random values. Salts have to be globally unique and using a good CSPRNG is the best way to achieve this.SHA1is most definitely not a good password hashing algorithm. This will fall very quickly to GPU-wielding attackers.Recommendations:
bcrypt. In PHP 5.5 and above, this can easily be done usingpassword_hash(). For older PHP versions, there is the excellent phpass library.admin/model/user/user.phpis not the only part of the code that suffers from this vulnerability. I noticed the same problem insystem/library/customer.php.Does opencart have a way to be contacted privately for security issues? I would prefer not to open an issue publicly in the future especially for more high-risk bugs.