[Security] Fix command injection in treeKill utility#7430
[Security] Fix command injection in treeKill utility#7430gonzaloriestra wants to merge 1 commit intomainfrom
Conversation
|
👋 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. |
b2fd339 to
9aab38a
Compare
🚨 Severity: CRITICAL 💡 Vulnerability: Command injection on Windows systems. 🎯 Impact: An attacker could execute arbitrary commands by providing a malicious PID string. 🔧 Fix: - Replaced the broken `Number.isNaN` PID validation with a robust regex check (`/^\d+$/`). - Replaced `child_process.exec` with `child_process.spawn` for the Windows `taskkill` command to prevent shell interpretation of arguments. - Added security comments explaining the fixes. ✅ Verification: - Added a new unit test file `packages/cli-kit/src/public/node/tree-kill.test.ts` to verify the fix. - Ran `pnpm lint` and `pnpm type-check` for `@shopify/cli-kit`. Made-with: Cursor
9aab38a to
f4de6ef
Compare
WHY are these changes introduced?
treeKillin@shopify/cli-kithad a critical command injection vulnerability on Windows. The PID validation usedNumber.isNaN(pid)against a string, which always returnsfalsefor non-NaNstring values, so malicious inputs like"1234; calc.exe"slipped through. The Windows branch then forwarded the value tochild_process.execvia string concatenation, which spawns a shell and interprets the injected command.WHAT is this pull request doing?
Number.isNaNPID check with a strict regex (/^\d+$/) so only digit-only strings are accepted.taskkillinvocation fromchild_process.exec(shell-based) tochild_process.spawnwith arguments passed as an array, eliminating shell interpolation.packages/cli-kit/src/public/node/tree-kill.test.tswith regression coverage for malicious and valid PID inputs.How to test your changes?
treeKillis invoked when you quitshopify app dev(it tears down the dev process tree). Build the CLI, run a dev session against any sample app, and confirm a graceful shutdown:Then sanity-check the new PID validation directly. With a malicious PID it should refuse to spawn anything and surface the validation error. Run from the repo root against the built bundle:
On Windows specifically, the
taskkillinvocation now usesspawnwith array arguments instead ofexecwith string concatenation. Reviewers on Windows can confirm by runningshopify app devand quitting — the child tree should still terminate.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add