Draft
Conversation
| from hashlib import sha1 | ||
| from base64 import b64encode | ||
| password = fn.get_password_bytes(password) | ||
| hashed = sha1(password).digest() |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic hashing algorithm on sensitive data
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we should replace the use of the SHA-1 hashing algorithm with a stronger, more secure algorithm suitable for password hashing. One of the best options is to use the argon2 algorithm, which is designed to be computationally expensive and includes a per-password salt by default.
Steps to fix:
- Import the
PasswordHasherclass from theargon2library. - Replace the SHA-1 hashing logic with the
argon2hashing logic. - Ensure that the new function maintains the same interface and functionality as the original.
Suggested changeset
2
src/passwordlib/unix/encrypt.py
| @@ -22,6 +22,6 @@ | ||
| def encrypt_sha1(password: t.AnyStr) -> str: | ||
| from hashlib import sha1 | ||
| from base64 import b64encode | ||
| from argon2 import PasswordHasher | ||
| password = fn.get_password_bytes(password) | ||
| hashed = sha1(password).digest() | ||
| return "{SHA1}" + b64encode(hashed).decode() | ||
| ph = PasswordHasher() | ||
| hashed = ph.hash(password) | ||
| return hashed |
Pipfile
Outside changed files
| @@ -8,2 +8,3 @@ | ||
|
|
||
| argon2-cffi = "^23.1.0" | ||
| [dev-packages] |
This fix introduces these dependencies
| Package | Version | Security advisories |
| argon2-cffi (pypi) | 23.1.0 | None |
Copilot is powered by AI and may make mistakes. Always verify output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.