Skip to content

Opencart's password hashing is vulnerable #1269

@Ayrx

Description

@Ayrx

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.

  1. 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.
  2. Three iterations of SHA1 is most definitely not a good password hashing algorithm. This will fall very quickly to GPU-wielding attackers.
Recommendations:
  1. Please read How to securely hash passwords? for password hashing best practices.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions