Repository navigation
Java: detect command injection through delegating launchers - #22818
Conversation
|
@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. |
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
6 open findings
ThisforallquantifiesSsaDefinition defbut then unconditionally castsdefto… · Newexists(...)is used with an expression (exists(this.getArgument(...))), which is not valid QL… · NewcommandOperandre-binds thelauncherparameter usingthis.getFixedArgument(_), which can… · Newexists(...)is used with an expression (exists(this.getArgument(...))), which is not valid QL… · NewisShellaccounts for Windows-style.exesuffixes, butisDelegatingLauncherdoes not. This… · NewunknownIndex[arg.length()]can throwArrayIndexOutOfBoundsExceptionfor most inputs (since the… · New
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
isSafeCommandArgumentto 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.
|
@copilot Address review comments. |
f1d360c to
f627764
Compare
78f0ba2 to
8f59bbb
Compare
I've changed my mind about supporting lots and lots of delegating launchers. Better to keep it simple.
|
DCA seems fine. |
There was a problem hiding this comment.
🟡 Changes recommended
Command-argument sanitization can suppress genuine injection alerts when derived containers are mutated or a launcher may resolve to a shell.
3 open issues
6 resolved since last review
exists(...)is used with an expression (exists(this.getArgument(...))), which is not valid QL…commandOperandre-binds thelauncherparameter usingthis.getFixedArgument(_), which can…exists(...)is used with an expression (exists(this.getArgument(...))), which is not valid QL… ThisforallquantifiesSsaDefinition defbut then unconditionally castsdefto…unknownIndex[arg.length()]can throwArrayIndexOutOfBoundsExceptionfor most inputs (since the…isShellaccounts for Windows-style.exesuffixes, butisDelegatingLauncherdoes not. This…
Review effort: Max
Co-authored-by: Copilot <[email protected]>
d6c8594 to
8b4e67c
Compare
|
I've just totally rewritten this PR to be much simpler. Old comments can be ignored. |
|
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. |


Improves
java/command-line-injectionto detect command injection through simple invocations of delegating launchers (env,sudo,xargs,nice,nohup,setsid,chroot,stdbuf, andtimeout).Approach
To keep
CommandArguments.qllsimple and avoid false positives, this extends the three existingisSafeCommandArgumentcases (ArrayInit,CommandArgumentList, andCommandArgArrayImmutableFirst) directly rather than introducing separate container/mutation tracking:0is not a shell.0may be a supported delegating launcher with fixed command positioncmdIndex(1or2), sanitization is withheld only if:cmdIndex, orcmdIndexand the element atcmdIndexmay 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:envKEY=VALUEassignments that shift the delegated command index.Addresses case 4 of #22262.