fix(python): detect standalone PyCA hash constructions#464
Open
sachin9058 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds detection and translation support for direct hash computations using cryptography.hazmat.primitives.hashes.Hash(...), along with new test fixtures to validate the rule behavior.
Changes:
- Introduces a new detection rule for
hashes.Hash(hashes.<ALG>())patterns and wires it into the Python rules registry. - Extends digest-context translation to accept
Algorithmvalues in addition toValueAction. - Adds a new Java test + Python fixture for the direct-hash wrapper case, and adjusts an elliptic-curve signing fixture.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/src/main/java/com/ibm/plugin/rules/detection/hash/PycaHash.java | Adds a new detection rule for direct hash wrapper usage and exposes it via wrapperRules() |
| python/src/main/java/com/ibm/plugin/rules/detection/PythonDetectionRules.java | Registers the new hash wrapper rules into the global Python detection rules list |
| python/src/main/java/com/ibm/plugin/translation/translator/contexts/PycaDigestContextTranslator.java | Updates digest translation gating logic to include Algorithm-valued detections |
| python/src/test/java/com/ibm/plugin/rules/detection/hash/PycaHashDirectTest.java | Adds a test asserting detection + translation of hashes.Hash(hashes.SHA256()) |
| python/src/test/files/rules/detection/hash/PycaHashDirectTest.py | Adds the Python source fixture for the new rule |
| python/src/test/files/rules/detection/asymmetric/EllipticCurve/PycaEllipticCurveSignTestFile.py | Simplifies the digest used in the ECDSA Prehashed fixture |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Sachin Kumar <[email protected]>
57a38e4 to
8226422
Compare
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.
Summary
Standalone PyCA hash constructions such as:
were not detected because the corresponding detection rules were not registered in the Python rule registry.
Root Cause
PycaHash detection rules existed but were not included in the top-level Python detection configuration. As a result, hash constructions were never evaluated during analysis.
Changes
Example
Before:
No finding produced.
After:
SHA256 is detected and included in analysis results.
Testing
Added regression test verifying SHA256 hash constructions are detected.