Potential fix for code scanning alert no. 5: Use of a broken or weak cryptographic hashing algorithm on sensitive data #4
+38
−6
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/ismailtsdln/GhidraInsight/security/code-scanning/5
In general, to fix this issue you should avoid using fast general-purpose hashes (like SHA‑256) for hashing secrets such as passwords or API keys for storage/verification. Instead, use a dedicated password hashing or key derivation function that is intentionally slow and salted, such as Argon2, scrypt, bcrypt, or PBKDF2 (via
hashlib.pbkdf2_hmacin the standard library).For this codebase, the minimal-impact fix is to change
AuthManager.hash_api_keyandAuthManager.verify_api_keyso that:hash_api_keyderives a key from the API key using PBKDF2‑HMAC with SHA‑256, a sufficiently large iteration count, and a per-key random salt.pbkdf2_sha256$<iterations>$<salt_hex>$<dk_hex>), so verification can reconstruct the same parameters.verify_api_keyparses that stored string, recomputes the PBKDF2 output, and compares using a constant-time comparison (hmac.compare_digest) to avoid timing side channels.Concretely, in
python-mcp/ghidrainsight/auth.py:hashlib.pbkdf2_hmac, with a fixed iteration count (e.g., 100_000) and a random salt fromsecrets.token_bytes.hash_api_keyto reflect that it’s using a strong password-hashing KDF (PBKDF2) rather than simple SHA‑256.verify_api_keyto:hmac.compare_digest.import hmacat the top ofauth.pysince we need it for constant‑time comparison.No changes are required in
python-mcp/ghidrainsight/cli/__init__.pybecause the CLI simply callsAuthManager.hash_api_key(api_key)and prints the returned string; changing the internal hash format keeps behavior consistent from the CLI’s perspective.Suggested fixes powered by Copilot Autofix. Review carefully before merging.