Skip to content

[Security] Fix command injection in treeKill on Windows#7439

Draft
gonzaloriestra wants to merge 1 commit intomainfrom
fix/security-command-injection-tree-kill-15462723101799022017
Draft

[Security] Fix command injection in treeKill on Windows#7439
gonzaloriestra wants to merge 1 commit intomainfrom
fix/security-command-injection-tree-kill-15462723101799022017

Conversation

@gonzaloriestra
Copy link
Copy Markdown
Contributor

Fixes a potential command injection vulnerability in the treeKill utility function when running on Windows.

Security Concern

The original code used Number.isNaN() to validate the pid argument before passing it to child_process.exec. Since pid can be a string, and Number.isNaN() returns false for non-numeric strings (unlike the global isNaN()), a malicious string like "123; calc.exe" would pass the check and be executed in a shell.

Fix

  1. Strict Validation: Used /^\d+$/ regex to ensure the PID contains only digits.
  2. Safer Execution: Switched from child_process.exec to child_process.spawn for the taskkill command. spawn executes the command directly without a shell, which prevents argument injection.
  3. Error Handling: Added an .on('error', ...) listener to the spawned process.

Testing

Added packages/cli-kit/src/public/node/tree-kill.test.ts which verifies:

  • Validation fails for malicious PID strings.
  • taskkill is called with the correct arguments on Windows using spawn.

Verified that pnpm --filter @shopify/cli-kit vitest src/public/node/tree-kill.test.ts passes.


PR created automatically by Jules for task 15462723101799022017 started by @gonzaloriestra

The `treeKill` function on Windows was using `child_process.exec` with a
PID that was improperly validated using `Number.isNaN()` on a string.
`Number.isNaN()` does not perform type coercion, so it would return
`false` for any non-numeric string, allowing shell metacharacters to be
passed to `exec`.

This change:
- Replaces the incorrect `Number.isNaN()` check with a strict regex
  validation `^\d+$`.
- Replaces `child_process.exec` with `child_process.spawn` for calling
  `taskkill`, avoiding shell execution.
- Adds an error listener to the spawned process to prevent unhandled
  exceptions.
- Adds a unit test to verify the fix and prevent regressions.
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant