fix(java): propagate nested cryptographic values across method parameters#432
fix(java): propagate nested cryptographic values across method parameters#432sachin9058 wants to merge 3 commits into
Conversation
…ters Signed-off-by: Sachin Kumar <sachinkumar905846@gmail.com>
|
Hi @n1ckl0sk0rtge @san-zrl I opened #433 separately since it appears independent from parameter propagation and I wanted to keep this PR scoped to nested value propagation. |
n1ckl0sk0rtge
left a comment
There was a problem hiding this comment.
PR Review
Linked Issue: #431 — "Nested cryptographic detections are not propagated when cryptographic values are passed as method parameters" (OPEN)
| Area | Status |
|---|---|
| CI / Build | ❌ FAILING — BcNTRUParametersTest regression |
| Requirements coverage | Partial — fix appears to work for #431 example, but test skips an extra finding without justification |
| Architecture | OK — changes stay within engine/language/java |
| Scope | ❌ CREEP — bundles an unrelated fix for #339 (UI location) |
| Security | No concerns |
| Tests | Re-enables existing ParameterValuesNotCapturedTest; no test for the JavaScanContext changes |
| Breaking changes | Internal only |
MUST FIX (Blocking)
1. [Build] CI build is failing — BcNTRUParametersTest regression
java/src/test/java/com/ibm/plugin/rules/detection/bc/cipherparameters/BcNTRUParametersTest.java:93- CI log shows
Expected size: 4 but was: 3— the AESBlockCiphernode now has only{BlockSize, Oid, Encrypt}, missing one child (most likelyKeyLengthor a mode marker). - Likely root cause: the change in
JavaLanguageTranslation.java:201removingmatchContext.isHookContext()from the type-match condition alters how hook-context parameter types are matched, breaking the detection chain foraesEngine.init(true, parameters). - Fix: Reproduce locally with
mvn -pl java test -Dtest=BcNTRUParametersTest, identify which child node was dropped, and either revert theJavaLanguageTranslationchange or add the hook-context branch back with a comment explaining why it is no longer needed.
2. [Scope] Bundled unrelated fix for issue #339
engine/src/main/java/com/ibm/engine/language/java/JavaScanContext.java(+54 lines — the biggest change in this PR)- The
extractPreciseTree()/reportIssue()refactor and the javadoc explicitly say "fixes the SonarQube UI issue location for cases like #339" — this is a separate concern from #431's parameter propagation. - Fix: Split into a second PR linked to #339. Keeping unrelated changes together makes the regression in MUST-FIX #1 hard to bisect — the offending change could be in either the parameter logic or the new
extractPreciseTreepath.
SHOULD FIX (Non-blocking)
3. [Logic] JavaLanguageTranslation.java:201 change is unjustified in the PR description
- The diff drops
matchContext.isHookContext() ||from the condition with no explanation. This is a behavior change for every hook-context match, not just the parameter-propagation path being fixed. Given finding #1, this is the most suspicious line in the PR. - Fix: Add a code comment and a PR-body note explaining why hook context should no longer trigger exact matching, with a test that fails without the change and passes with it.
4. [Tests] No coverage for the new JavaScanContext precise-location logic
- Three new branches (
NEW_CLASS,METHOD_INVOCATION, default fallback) are added with no unit test. - Fix: Add a small test (e.g.
JavaScanContextTest) that asserts the reported issue location for each case —new AESEngine()reports atAESEngine,obj.method()reports atmethod, other kinds fall back tofirstToken().
5. [Tests] Extra finding skipped in ParameterValuesNotCapturedTest without explanation
java/src/test/java/com/ibm/plugin/rules/issues/ParameterValuesNotCapturedTest.java:71— changed fromfindingId == 0tofindingId == 0 || findingId == 2. The existing TODO already calls out that these "direct detections of engines… appear in the depending detection rules"; adding finding 2 to the skip list quietly may mask a duplicate-detection regression introduced by the new parameter hook.- Fix: In the test javadoc/comment, document what finding 2 represents and why it is expected to duplicate finding 1 (or fix the duplication if unintended).
6. [Style] Fully-qualified class names instead of imports in JavaDetectionEngine.java:863–879
- Uses
org.sonar.plugins.java.api.tree.IdentifierTree,…VariableTree,…MethodTree, andorg.sonar.java.model.ExpressionUtilsinline. The rest of the file uses imports. - Fix: Add normal imports and use simple names — consistent with file style and the project's Spotless/Checkstyle config.
SUGGESTIONS
7. [Heuristic] Parameter-detection heuristic in JavaDetectionEngine.java:864
variableTree.initializer() == nullis meant to identify method parameters, but it also matches declared-but-not-yet-initialized locals (String x; …). For the next iteration considervariableTree.parent().is(Tree.Kind.METHOD)or checking the symbol's owner is a method, which is more precise.
8. [Maintenance] extractPreciseTree duplicates token-selection logic
- The javadoc says this mirrors
JavaTranslator.getDetectionContextFrom(). Two parallel implementations will drift. Consider extracting to a single utility incommon/(or referencing the existing one).
Notes
- The fix idea for #431 (recognize parameter identifiers and re-enter analysis at the caller site via
createAMethodHook) is sound and the re-enabled regression test demonstrates value. - Please split the #339-related
JavaScanContextchanges into their own PR — keeping them here makes the failingBcNTRUParametersTestmuch harder to triage. - Once the CI failure is investigated and #339 is split out, this PR will be in much better shape to merge.
|
@n1ckl0sk0rtge Thanks for the detailed review. I agree that the JavaScanContext changes are unrelated to #431 and should be split out. I'll remove the #339-related changes from this PR and keep the focus on parameter propagation. I'll also investigate the BcNTRUParametersTest regression and review the JavaLanguageTranslation change around hook-context matching to determine whether it is responsible for the missing child node. Thanks for pointing out the additional test/documentation gaps as well. |
…eters Signed-off-by: Sachin Kumar <sachinkumar905846@gmail.com>
00443db to
9757b50
Compare
Signed-off-by: Sachin Kumar <sachinkumar905846@gmail.com>
|
Hi @n1ckl0sk0rtge, I've addressed the review items:
Validation:
Thanks for the review happy to make any further adjustments if needed. |
Description
This PR resolves an issue where nested cryptographic detections are lost when cryptographic values are passed through method parameters.
During analysis, parameter variables were only evaluated inside the local method scope and the original values supplied by the caller were not propagated into the final detection hierarchy.
As a result, nested cryptographic implementations disappeared when helper methods, wrappers, or delegated constructions were used.
Reproduction
Example:
Expected behavior
Additional parameter values should also remain available:
Previous behavior
The nested
AESEnginedetection was missing.Changes
ParameterValuesNotCapturedTestParameterValuesNotCapturedTestFileValidation
Executed locally:
mvn -pl java test -Dtest=ParameterValuesNotCapturedTestResult:
Related issue
Fixes #431