Skip to content

NEW @W-23766007@ Feature/h1 java command relative path fix - #496

Merged
nikhil-mittal-165 merged 6 commits into
devfrom
feature/h1-java-command-relative-path-fix
Aug 12, 2026
Merged

NEW @W-23766007@ Feature/h1 java command relative path fix#496
nikhil-mittal-165 merged 6 commits into
devfrom
feature/h1-java-command-relative-path-fix

Conversation

@nikhil-mittal-165

Copy link
Copy Markdown
Contributor

No description provided.

…ative java_command paths

Adds a shared helper that accepts only bare PATH command names or absolute
paths for java_command, rejecting repo-relative paths that could resolve to a
repository-controlled executable. Bumps engine-api to 0.42.0-SNAPSHOT and
cascades the dependency bump to all consuming packages.

Part of the H1 bug bounty RCE fix.
… and cpd

extractJavaCommand now validates the user-specified java_command via the shared
ValueValidator.validateJavaCommand helper BEFORE calling identifyJavaVersion, so
a repo-relative executable path in an auto-discovered config is never spawned.
Bare command names and absolute paths continue to work unchanged.

Part of the H1 bug bounty RCE fix.
SfgeConfigValueExtractor.extractJavaCommand now validates the user-specified
java_command via the shared ValueValidator.validateJavaCommand helper BEFORE
calling identifyJavaVersion, so a repo-relative executable path in an
auto-discovered config is never spawned. Bare command names and absolute paths
continue to work unchanged.

Part of the H1 bug bounty RCE fix.
…e java_command

Reproduces the H1 PoC using core stubs: an auto-discovered config sets a
relative engines.pmd.java_command, and a JavaVersionIdentifier spy fails the
test if the binary is ever spawned. Asserts the malicious PMD engine fails to
instantiate without spawning, addEnginePlugin does not throw, and an
eslint-only selectRules still succeeds (per-engine failure isolation).

Part of the H1 bug bounty RCE fix.
Code review found 3 issues with the java_command security fix:

- Added clarifying comment about absolute-path limitation: auto-discovered configs
  can still set absolute paths to repo-controlled binaries. This fix mitigates
  relative paths but doesn't fully close the threat model.
- Fixed Windows drive-relative path bypass (e.g., 'C:foo') by checking for ':'
  in bare command names, preventing drive-relative path resolution.
- Removed redundant path.sep check and replaced with ':' validation for
  cross-platform correctness.
- Fixed missing newline at end of pmd-engine test file.

Reviewed-by: Claude (code-review agent)
Fixed-by: Claude (Anthropic)
@git2gus

git2gus Bot commented Aug 10, 2026

Copy link
Copy Markdown

Git2Gus App is installed but the .git2gus/config.json doesn't have right values. You should add the required configuration.

@aruntyagiTutu aruntyagiTutu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against the Code Analyzer PR Review guidelines.

Summary: Fixes a relative-java_command PATH-hijack risk (CWE-427-adjacent, similar in spirit to the cwd-shadowing fix in #495) by rejecting relative paths in ValueValidator.validateJavaCommand before spawning java for PMD/CPD and SFGE. Validation runs before validateJavaCommandContainsValidVersion (which spawns java) in both engines' config extraction — no unguarded spawn path.

Verified the boundary is correct: bare PATH-resolved names (java) and absolute paths are allowed; ./java, ../java, and other relative paths are rejected — matches the intended threat model without breaking normal PATH-based java resolution.

Confirmed the follow-up "address code review findings" commit (9006b01) fixed a real cross-platform gap: the original check used !strValue.includes(path.sep), which never actually caught Windows drive-relative paths like C:foo (path.isAbsolute('C:foo') is false, and path.sep checks are redundant with the separator checks already in place). The fix added an explicit : check, closing that bypass. Good catch by whoever flagged it, and it's fully resolved now.

Test coverage is solid — java-command-security.test.ts uses a spy that fails the test if the java-version-check function is ever invoked, proving rejection happens pre-spawn, not just at a validation layer that could be bypassed later. CI is green across macOS/Ubuntu/Windows.

Two non-blocking items worth a follow-up (not blockers here):

  1. The validator's own docstring notes that absolute-but-repo-controlled paths, and auto-discovered configs overriding java_command for unselected engines, are still unmitigated — worth a GUS ticket per the PR hygiene norm of tracking known-remaining scope rather than letting it go untracked.
  2. validateJavaCommand('') returns '' as a "valid" bare command (no separators to trip the check) — not currently reachable since call sites guard on falsy javaCommand first, but worth tightening the validator itself since callers could change.

Approving the direction; these are cleanup items, not blockers.

@nikhil-mittal-165

Copy link
Copy Markdown
Contributor Author

created this ticket : https://gus.lightning.force.com/lightning/r/ADM_Work__c/a07EE00002hEvriYAC/view
for a followup on the above 2 points

@nikhil-mittal-165
nikhil-mittal-165 merged commit 5f1fced into dev Aug 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants