-
Notifications
You must be signed in to change notification settings - Fork 0
[Security] Fix CodeQL alert #16: Use of a broken or weak cryptographic hashing algorithm on sensitive data #90
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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from Crypto.Hash import MD5, SHA1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def hash_password_weak(password): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return hashlib.md5(password.encode()).hexdigest() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return hashlib.sha256(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, password hashing must use a dedicated, slow, memory-hard password hashing scheme such as Argon2, scrypt, bcrypt, or PBKDF2, rather than a fast general-purpose hash like SHA-256. These algorithms also incorporate salts and parameters (iterations, memory cost, parallelism) to make brute-force attacks impractical. For this specific code, the minimal-impact fix is to change
This preserves the outward behavior (input: password string; output: hash string) while making the hashing algorithm computationally expensive and salted.
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 between password hashing and verificationHigh Severity
Additional Locations (1) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def hash_with_sha1(data): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return hashlib.sha1(data.encode()).hexdigest() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


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 between hash_password_weak (now SHA256) and verify_password (still MD5)
The PR updated
hash_password_weakfrom MD5 to SHA256, but the correspondingverify_passwordfunction atvulnerable_weak_crypto.py:40still useshashlib.md5to compute the hash for comparison. If a password is stored usinghash_password_weak(SHA256) and later verified usingverify_password(MD5), the hashes will never match, causing all password verifications to fail.(Refers to line 40)
Was this helpful? React with 👍 or 👎 to provide feedback.