Potential fix for code scanning alert no. 96: Use of a broken or weak cryptographic hashing algorithm on sensitive data #8441
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.



Potential fix for https://github.com/ITISFoundation/osparc-simcore/security/code-scanning/96
To fix this issue, use a password/secret hashing function for generating API keys based on user input if they are intended as secrets or authentication tokens (i.e., if knowledge of the key grants access). Strong choices are Argon2, bcrypt, or PBKDF2. Since deterministic generation is needed (so the same name generates the same key), PBKDF2 is the most practical among these, allowing a fixed secret salt (ideally not public) to be set. If stricter determinism without secret salt is required, we may use SHA-2 (SHA-256/512), but only if the API key isn't used as a credential (which is discouraged). For best security, switch to PBKDF2 using your own application-wide salt (hardcoded or configurable, but never exposed to users).
Therefore, replace the SHA256 hashing with PBKDF2 using a strong ("pepper") salt and an appropriately high number of iterations for reasonable computational expense. Make sure to import and use
hashlib.pbkdf2_hmac.Changes required:
hashlib.sha256(name.encode()).hexdigest()call with a PBKDF2-HMAC using SHA256 and the constant salt, with a highiterationsparameter.osif needed for salt (or simply declare a constant).hashlib.pbkdf2_hmacis available from Python standard library ≥3.4).Suggested fixes powered by Copilot Autofix. Review carefully before merging.