Skip to content

Java: detect command injection through delegating launchers - #22818

Merged
owen-mc merged 1 commit into
mainfrom
copilot/fix-is-safe-command-argument
Nov 20, 2026
Merged

owen-mc merged 1 commit into
mainfrom
copilot/fix-is-safe-command-argument

Conversation

Copilot AI commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Improves java/command-line-injection to detect command injection through simple invocations of delegating launchers (env, sudo, xargs, nice, nohup, setsid, chroot, stdbuf, and timeout).

Approach

To keep CommandArguments.qll simple and avoid false positives, this extends the three existing isSafeCommandArgument cases (ArrayInit, CommandArgumentList, and CommandArgArrayImmutableFirst) directly rather than introducing separate container/mutation tracking:

  • Non-initial arguments remain sanitized by default when index 0 is not a shell.
  • When index 0 may be a supported delegating launcher with fixed command position cmdIndex (1 or 2), sanitization is withheld only if:
    • the argument itself can appear at cmdIndex, or
    • the argument appears after cmdIndex and the element at cmdIndex may itself be a shell or delegating launcher.

Intentional limitations

To prioritize simplicity and keep false-positive risk low (matching existing heuristics for index 0), the following are intentionally not modeled:

  • Launcher flags and env KEY=VALUE assignments that shift the delegated command index.
  • Unresolved variables/parameters in the delegated command position.
  • Post-hoc element mutations of array initializers that already contain the tainted argument.

Addresses case 4 of #22262.

Copilot AI changed the title [WIP] Fix isSafeCommandArgument to account for delegating launchers Java: detect command injection through delegating launchers Oct 14, 2026
Copilot AI requested a review from owen-mc October 14, 2026 10:42
@github-actions github-actions Bot added the Java label Oct 14, 2026
@owen-mc

owen-mc commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@copilot Please address the three comments on this PR.

Copilot AI commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the three comments on this PR.

Addressed all three comments in edb67fe and 866d93b. Launcher handling now preserves safe arguments after fixed non-shell commands, recognizes the missing wrappers, and includes GOOD cases for literals, lists, and mutable arrays. Added safeguards and regressions for unresolved commands and mutated aliases. All four CWE-078 tests pass; final read-only review found no issues. The automated security scan was skipped because its database was too large.

Copilot AI 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.

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

6 open findings
What changed in this PR

Updates the Java CWE-078 CodeQL modeling and tests to better distinguish delegating “launcher” executables (for example env, sudo, timeout) from shells, improving command-injection and relative-path detection accuracy.

Changes:

  • Extend isSafeCommandArgument to handle delegating launchers by analyzing fixed command prefixes across arrays/lists/mutable arrays.
  • Add new test cases covering launcher delegation scenarios and update expected query outputs accordingly.
  • Introduce new argument-sequence abstraction (CommandArguments) and supporting utilities for alias/escape tracking.
File Description
java/​ql/​test/​query-tests/​security/​CWE-078/​Test.java Adds new ProcessBuilder test cases for delegating launchers, argument mutation/aliasing, and fixed-vs-tainted scenarios.
java/​ql/​test/​query-tests/​security/​CWE-078/​ExecTainted.expected Updates expected taint-tracking results to include new test cases and shifted line numbers.
java/​ql/​test/​query-tests/​security/​CWE-078/​ExecRelative.expected Updates expected relative-path command results for newly added launcher cases and shifted line numbers.
java/​ql/​lib/​semmle/​code/​java/​security/​CommandArguments.qll Implements launcher-aware safe-argument logic, including prefix inspection and container escape tracking.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@owen-mc

owen-mc commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@copilot Address review comments.

Copilot AI commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Address review comments.

Addressed in 8f39336. Fixed the launcher operand binding and review findings, added .exe launcher coverage, and made the dynamic array index safe.

@owen-mc
owen-mc force-pushed the copilot/fix-is-safe-command-argument branch 4 times, most recently from f1d360c to f627764 Compare October 16, 2026 16:13
@owen-mc
owen-mc force-pushed the copilot/fix-is-safe-command-argument branch 2 times, most recently from 78f0ba2 to 8f59bbb Compare October 16, 2026 18:22
@owen-mc
owen-mc marked this pull request as ready for review October 17, 2026 09:20
@owen-mc
owen-mc requested a review from a team as a code owner October 17, 2026 09:20
@owen-mc
owen-mc dismissed their stale review October 17, 2026 09:22

I've changed my mind about supporting lots and lots of delegating launchers. Better to keep it simple.

@owen-mc
owen-mc removed their request for review October 20, 2026 10:02
@owen-mc
owen-mc requested a max review from Copilot November 4, 2026 16:48
@owen-mc

owen-mc commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

DCA seems fine.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

@owen-mc
owen-mc force-pushed the copilot/fix-is-safe-command-argument branch from d6c8594 to 8b4e67c Compare November 20, 2026 12:10
@owen-mc

owen-mc commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

I've just totally rewritten this PR to be much simpler. Old comments can be ignored.

@aschackmull aschackmull 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.

Looks reasonable.

@owen-mc

owen-mc commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

DCA wasn't clean but it seems like noise. The failing integration test seems unrelated. I'll give it one more rerun and then merge anyway.

@owen-mc
owen-mc merged commit aafa7de into main Nov 20, 2026
24 of 25 checks passed
@owen-mc
owen-mc deleted the copilot/fix-is-safe-command-argument branch November 20, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants