-
Notifications
You must be signed in to change notification settings - Fork 0
[Security] Fix CodeQL alert #21: Use of a broken or weak cryptographic algorithm #95
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,9 +41,12 @@ def verify_password(input_password, stored_hash): | |||||||||||||||||
| return input_hash == stored_hash | ||||||||||||||||||
|
|
||||||||||||||||||
| def encrypt_sensitive_data(data): | ||||||||||||||||||
| key = b'weakkey1' | ||||||||||||||||||
| cipher = DES.new(key, DES.MODE_ECB) | ||||||||||||||||||
| return cipher.encrypt(data.encode().ljust(8)) | ||||||||||||||||||
| from Crypto.Cipher import AES | ||||||||||||||||||
| from Crypto.Random import get_random_bytes | ||||||||||||||||||
| key = get_random_bytes(32) | ||||||||||||||||||
| cipher = AES.new(key, AES.MODE_GCM) | ||||||||||||||||||
| ciphertext, tag = cipher.encrypt_and_digest(data.encode()) | ||||||||||||||||||
| return cipher.nonce + tag + ciphertext | ||||||||||||||||||
|
Comment on lines
+46
to
+49
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. 🔴 Encryption key is generated randomly but never returned, making decryption impossible The new
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||
|
|
||||||||||||||||||
| def generate_otp(): | ||||||||||||||||||
| return str(random.randrange(100000, 999999)) | ||||||||||||||||||
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.
Random encryption key generated but never returned
High Severity
encrypt_sensitive_datagenerates a randomkeyviaget_random_bytes(32)but only returns the nonce, tag, and ciphertext — the key is discarded when the function returns. This means the encrypted data can never be decrypted. The previous (insecure) implementation used a hardcoded key, which at least allowed decryption. The fix swapped a security problem for a complete loss of functionality.