Skip to content

JS: Ignore positional parameters to sh -c in command injection - #23284

Open
owen-mc wants to merge 2 commits into
github:mainfrom
owen-mc:copilot/fix-js-sh-c-positional-params
Open

owen-mc wants to merge 2 commits into
github:mainfrom
owen-mc:copilot/fix-js-sh-c-positional-params

Conversation

@owen-mc

@owen-mc owen-mc commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Only treat the command_string operand of sh/bash -c invocations as a command-injection sink when its position can be determined, ignoring subsequent positional parameters ($0, $1, ...). Fall back to existing whole-array behavior when array mutations, spreads, or uncertain flags make the command_string position ambiguous, and preserve Windows cmd.exe /c behavior.

Fixes #23274

@owen-mc
owen-mc requested review from a team and an adaptive review from Copilot November 27, 2026 13:39

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.

🟡 Changes recommended

Argument narrowing can omit executed, attacker-controlled shell input in dynamic-option, mutated-array, ambiguous-origin, and shell-interpreted operand cases, creating critical command-injection false negatives.

6 open issues
What changed in this PR

Refines JavaScript command-injection analysis to distinguish sh -c and bash -c scripts from positional data, addressing the false positives reported in #23274.

Changes:

  • Adds argument-prefix and shell-option tracking to select command-string sinks while preserving Windows cmd.exe /c behavior.
  • Adds regression cases across four command-injection query suites and updates expected results.
  • Documents the analysis change.
File Description
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​UnsafeShellCommandConstruction/​UnsafeShellCommandConstruction.expected Updates expected library-input alerts.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​UnsafeShellCommandConstruction/​lib/​lib.js Contrasts positional data with concatenated shell code.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​ShellCommandInjectionFromEnvironment/​tst_shell-command-injection-from-environment.js Adds environment-derived positional and script cases.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​ShellCommandInjectionFromEnvironment/​ShellCommandInjectionFromEnvironment.expected Updates environment-query results and flow paths.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​IndirectCommandInjection/​IndirectCommandInjection.expected Adds the expected tainted-script result.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​IndirectCommandInjection/​command-line-parameter-command-injection.js Adds positional, concatenated-array, and unsafe-script cases.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​CommandInjection/​CommandInjection.expected Updates direct-query alerts and flow paths.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​CommandInjection/​child_process-test.js Adds shell-option, positional, concatenation, and mutation cases.
javascript/​ql/​lib/​semmle/​javascript/​security/​dataflow/​IndirectCommandArgument.qll Implements shell-specific command-operand selection.
javascript/​ql/​lib/​change-notes/​2026-11-27-sh-c-positional-parameters.md Documents reduced positional-argument false positives.

Review effort: Max (adaptive)

owen-mc and others added 2 commits December 3, 2026 12:11
Only treat the command_string operand of sh/bash -c invocations as a
command-injection sink when its position can be determined, ignoring
subsequent positional parameters ($0, $1, ...). Fall back to existing
whole-array behavior when array mutations, spreads, or uncertain flags
make the command_string position ambiguous, and preserve Windows
cmd.exe /c behavior.

Fixes github#23274

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Share `isUnixDashC` between `isIndirectCommandArgument` and
`unixCommandStringIndex` so bundled short flags such as `sh -ec` and
`bash -lc` are recognized while still ignoring positional parameters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@owen-mc
owen-mc force-pushed the copilot/fix-js-sh-c-positional-params branch from ae2c7ee to 6f7183e Compare December 3, 2026 15:18
@owen-mc
owen-mc marked this pull request as ready for review December 3, 2026 15:24
@owen-mc
owen-mc requested a review from a team as a code owner December 3, 2026 15:24

This branch has not been deployed

No deployments
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.

JS: false positive in js/command-line-injection on sh -c positional parameters ($1/$@)

3 participants