weak-password-hash
A password hashed with a fast digest.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule weak-password-hash - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
A password is hashed with MD5 or SHA-1, which are fast enough that a stolen hash can be guessed by trying billions of passwords a second. Hash passwords with bcrypt, scrypt, or Argon2, as Rails' has_secure_password does.
The fix, as Ur suggests it: hash it with bcrypt.
For agents
Never hash passwords with MD5 or SHA-1; use bcrypt, scrypt, or Argon2.
Example
app/models/user.rbclass User < ApplicationRecord
before_save :hash_password
def hash_password
self.password = Digest::MD5.hexdigest(password)
end
end
$ ur scan --rule weak-password-hash
warning[weak-password-hash]: a password is hashed with `Digest::MD5.hexdigest`, which is fast to guess
--> ./app/models/user.rb:5:21 module's top level
= hint: hash it with bcrypt
= see: CWE-916: Use of Password Hash With Insufficient Computational Effort, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/916.html
scanned 1 file (no framework recognized)
weak-password-hash: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
CWE-916: Use of Password Hash With Insufficient Computational Effort, MITRE (2024-11-19).