[Security] Fix command injection in treeKill on Windows#7439
[Security] Fix command injection in treeKill on Windows#7439gonzaloriestra wants to merge 1 commit intomainfrom
Conversation
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.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Fixes a potential command injection vulnerability in the
treeKillutility function when running on Windows.Security Concern
The original code used
Number.isNaN()to validate thepidargument before passing it tochild_process.exec. Sincepidcan be a string, andNumber.isNaN()returnsfalsefor non-numeric strings (unlike the globalisNaN()), a malicious string like"123; calc.exe"would pass the check and be executed in a shell.Fix
/^\d+$/regex to ensure the PID contains only digits.child_process.exectochild_process.spawnfor thetaskkillcommand.spawnexecutes the command directly without a shell, which prevents argument injection..on('error', ...)listener to the spawned process.Testing
Added
packages/cli-kit/src/public/node/tree-kill.test.tswhich verifies:taskkillis called with the correct arguments on Windows usingspawn.Verified that
pnpm --filter @shopify/cli-kit vitest src/public/node/tree-kill.test.tspasses.PR created automatically by Jules for task 15462723101799022017 started by @gonzaloriestra