Skip to content

Fix shell command injection in tool execution and PR creation - #5152

Merged
Lauren Prinn (laurenprinn) merged 5 commits into
mainfrom
alert-autofix-47
Nov 6, 2026
Merged

Lauren Prinn (laurenprinn) merged 5 commits into
mainfrom
alert-autofix-47

Conversation

@laurenprinn

@laurenprinn Lauren Prinn (laurenprinn) commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

General fix approach: stop building shell command strings with interpolated input and stop using execSync with a single command string. Instead, execute git with cp.execFileSync and pass arguments as an array so user-controlled values are treated as data, not shell syntax.

Best single fix in this snippet: refactor runGit to accept command: string[] and invoke cp.execFileSync("git", [...gitConfigArgs, ...command]). Then update call sites in shown code to pass argument arrays (especially line 232 cleanup delete-branch call). Keep behavior equivalent by preserving logging and auth/config handling, but avoid shell interpretation entirely.

Edits needed in tools/pr-creator/src/index.ts:

  • Change runGit signature and implementation (lines around 109–121).
  • Update sourceBranchAlreadyExists and cleanup callers to pass arrays instead of interpolated command strings.
  • No new dependency required; child_process already imported.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…rary input

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
@laurenprinn Lauren Prinn (laurenprinn) changed the title Potential fix for code scanning alert no. 47: Unsafe shell command constructed from library input Nov 6, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 93ca34e1-42aa-4082-8c31-20eb605a6d28
@laurenprinn Lauren Prinn (laurenprinn) changed the title Fix for code scanning alerts: Unsafe shell command constructed from library input Nov 6, 2026
Comment thread src/proc.ts Fixed
@laurenprinn
Lauren Prinn (laurenprinn) marked this pull request as ready for review November 6, 2026 01:03
Comment thread src/proc.ts Resolved
Avoid passing generated batch paths directly to cmd.exe /c in the no-shell execution branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve with feedback (offline)

@laurenprinn
Lauren Prinn (laurenprinn) merged commit 87f75d8 into main Nov 6, 2026
33 checks passed
@laurenprinn
Lauren Prinn (laurenprinn) deleted the alert-autofix-47 branch November 6, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants