Repository navigation
fix: [BUG][code-analyzer] 5.16.0 silently drops custom PMD rulesets that point at a sibling file by relative path - #516
nikhil-mittal-165 wants to merge 2 commits into
Conversation
…ustom rulesets resolve Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Git2Gus App is installed but the |
|
Self-review using the refreshed Code Analyzer regression-review skill. Finding[P1] Do not restore the untrusted repository as a general Java classpath root PR #503 pinned the Java cwd specifically to address CWE-427. Adding Manual validation before mergeRequired:
Evidence checked: linked issue #2087, regression lineage from core PR #503, all changed invocations/callers, the new unit fixture, and green Linux/macOS/Windows CI. The functional CLI reproduction in the PR description is author-supplied evidence. |
…a classpath Adding process.cwd() to the PMD classpath re-exposed the scanned repository to the JVM as a source of classes and resources (CWE-427, see #503). Instead, copy only the xml ruleset files that custom rulesets reference (transitively, and never from outside the base folder, including via symlinks) into a staging folder in the working folder and put just that folder last on the classpath. Repo-relative rule refs keep resolving (#2087). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Addressed the P1 finding in 7fd77a8: 🤖 Generated with Claude Code |
Summary
Addresses code-analyzer issue 2087: 5.16.0 silently drops custom PMD rulesets that point at a sibling file by relative path.
Root Cause
Regression from code-analyzer-core PR 503 (CWE-427 hardening):
JavaCommandExecutor.exec(code-analyzer-engine-api/src/utils/java-utils.ts) now spawns java withcwd=__dirname(engine install dir) instead of the inherited scanned-repo cwd. The PR assumed pinning cwd was behavior-preserving because all java args are absolute, but PMD resolves rule/ruleset refs written inside a user's custom ruleset (e.g.<rule ref="scanner/full.xml/MyRule"/>) first as a path relative to the process cwd, then as a classpath resource. Previously the cwd lookup found the file; now it fails, the PMD ruleset load errors, and the engine is dropped with a single file-less Critical violation and exit code 0. The config is valid per docs, the cwd-relative ref was undocumented but long-working behavior, and the PMD version (7.26.0) is unchanged between 5.15 and 5.16.The separate concern that an engine load failure exits 0 is not addressed by this fix.
Fix
Keep the cwd pin (security) and add the scan folder (
process.cwd()) to the PMD java classpath so repo-relative rule refs in custom rulesets resolve as classpath resources. Includes a test and a doc note in thecustom_rulesetsdescription.Testing
Functional Testing Evidence
Synthetic repro (not a real-world project):
scanner/full.xmldefinesMyRule,scanner/subset.xmlhas<rule ref="scanner/full.xml/MyRule"/>,code-analyzer.ymllists both underengines.pmd.custom_rulesets. Run vianode code-analyzer/bin/run.js(sf CLI not installed), Java 17 via Homebrew.code-analyzer rules --rule-selector pmd:MyRulefrom repo root ->1 MyRule pmd 3 (Moderate) Recommended, Full, Subset, Apex, Custom; Found 1 rule(s) from 1 engine(s)- PASSFailed to get rules from engine with name pmd ... Cannot load ruleset scanner/full.xml/MyRule: Cannot resolve- bug reproduced, PASScode-analyzer run --rule-selector pmd:MyRule --workspace src->pmd:MyRule A.cls:1:25 my rule hit- PASS. The only other violation was an unrelated flow-engine Critical because Python is not installed.Overall functional status: PASS
Files Changed
🤖 Generated with Claude Code