-
Notifications
You must be signed in to change notification settings - Fork 0
[Security] Fix CodeQL alert #18: Use of a broken or weak cryptographic hashing algorithm on sensitive data #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| return MD5.new(password.encode()).hexdigest() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def verify_password(input_password, stored_hash): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| input_hash = hashlib.md5(input_password.encode()).hexdigest() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| input_hash = hashlib.sha256(input_password.encode()).hexdigest() | ||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Use of a broken or weak cryptographic hashing algorithm on sensitive data High Sensitive data (password) Error loading related location Loading
Copilot AutofixAI 2 months ago In general, the fix is to replace the use of a fast, general-purpose hash (SHA-256) for password verification with a dedicated password hashing algorithm that is intentionally slow and parameterizable, such as Argon2, bcrypt, scrypt, or PBKDF2. This should be done both where passwords are initially hashed for storage and where they are later verified, so that the same strong algorithm is used consistently. In this file, the minimal, behavior-preserving fix (aside from improving security) is to change
Suggested changeset
1
vulnerable_weak_crypto.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Hash algorithm mismatch: verify_password uses SHA256 but companion hashing functions use MD5 The Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||||||||||||||||||||||
| return input_hash == stored_hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def encrypt_sensitive_data(data): | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hash algorithm mismatch breaks password verification
High Severity
verify_passwordnow useshashlib.sha256butPasswordHasher.hashstill usesMD5.newto create stored hashes. Since the hashing and verification functions use different algorithms,verify_passwordwill never produce a hash that matches one created byPasswordHasher.hash, causing all password verification to fail.Additional Locations (1)
vulnerable_weak_crypto.py#L36-L37