Skip to content

feat(java): detect cmd.exe ArgumentListBuilder.addTokenized (CWE-78) - #189

Open
ai-anant wants to merge 1 commit into
CodeVigilant:mainfrom
ai-anant:rule/jenkins-cmd-exe-addtokenized
Open

ai-anant wants to merge 1 commit into
CodeVigilant:mainfrom
ai-anant:rule/jenkins-cmd-exe-addtokenized

Conversation

@ai-anant

Copy link
Copy Markdown

Summary

Adds a Jenkins/Java rule that flags ArgumentListBuilder.addTokenized(...) used on a command list that also contains cmd.exe.

On Windows, Launcher reconstructs the token list into a command line that cmd.exe re-parses. Whitespace-split non-literal input (job parameters, process output, workspace file lines) can therefore inject cmd metacharacters as extra commands.

Pattern (generic)

ArgumentListBuilder b = new ArgumentListBuilder();
b.add("cmd.exe");
b.add("/c");
b.addTokenized(untrusted);
launcher.launch().cmds(b);

Quiet when addTokenized is a string literal, when the builder never adds cmd.exe, or when the untrusted value is passed with add() (one argv slot, no tokenize).

Why

addTokenized is often assumed safe because it builds an argv list rather than a shell string. That assumption fails once cmd.exe is the executable: the shell metacharacters become separate tokens and are then interpreted by cmd.

Validation

  • semgrep --validate --config java/ clean
  • Positive repro (cmd.exe + addTokenized of a non-literal) fires
  • Negative repro (literal tokenize / no cmd.exe / add() not addTokenized) silent

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.

1 participant