Skip to content

JS: Enhance command injection detection for CLI argument parsing libraries #20151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Aug 1, 2025

Improved modeling of command-line argument parsing libraries:

@github-actions github-actions bot added the JS label Aug 1, 2025
@Napalys Napalys marked this pull request as ready for review August 1, 2025 13:04
@Napalys Napalys requested a review from a team as a code owner August 1, 2025 13:04
@Copilot Copilot AI review requested due to automatic review settings August 1, 2025 13:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances command injection detection by improving the modeling of four popular command-line argument parsing libraries: arg, args, command-line-args, and commander. The changes enable better taint tracking from user input through these libraries to identify potential command injection vulnerabilities.

Key Changes

  • Enhanced taint flow modeling for commander, yargs, arg, and command-line-args libraries
  • Added comprehensive test cases covering various usage patterns of these libraries
  • Updated expected test results to include new command injection detection alerts

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
command-line-libs.js New test file demonstrating command injection vulnerabilities through various CLI parsing libraries
CommandInjection.expected Updated expected results including new alerts for CLI library-based command injections
CommandLineArguments.qll Enhanced taint tracking logic for arg, command-line-args, commander, and yargs libraries
2025-08-01-cli-code-injection.md Change notes documenting the improved CLI library modeling

@@ -87,11 +87,43 @@ private class ArgsParseStep extends TaintTracking::SharedTaintStep {
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
exists(DataFlow::CallNode call |
call = DataFlow::moduleMember("args", "parse").getACall() or
call = DataFlow::moduleImport(["yargs-parser", "minimist", "subarg"]).getACall()
call =
DataFlow::moduleImport(["yargs-parser", "minimist", "subarg", "yargs/yargs", "yargs"])
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

The module import list includes both "yargs/yargs" and "yargs" which could cause duplicate taint tracking for the same library. The "yargs" entry should be removed here since yargs is handled separately in the yargs() function below.

Suggested change
DataFlow::moduleImport(["yargs-parser", "minimist", "subarg", "yargs/yargs", "yargs"])
DataFlow::moduleImport(["yargs-parser", "minimist", "subarg", "yargs/yargs"])

Copilot uses AI. Check for mistakes.

.getArgument(0)
.(DataFlow::FunctionNode)
.getAParameter()
]
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

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

This logic assumes the action callback always receives parameters, but commander actions can be called without parameters. This could miss taint flow when the action function has no parameters but still processes command arguments through other means.

Suggested change
]
// Propagate to both the function node itself and its parameters
as DataFlow::Node
]

Copilot uses AI. Check for mistakes.

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.

1 participant