fix(deploy): prevent Windows shell injection - #1946
Conversation
commit: |
|
|
/bigbonk review for issues |
There was a problem hiding this comment.
Review: fix(deploy): prevent Windows shell injection
Reviewed the full diff, traced both commits, verified bin resolution against the real pnpm-installed wrangler@4.80.0, ran vp test run tests/deploy.test.ts (266/266 pass), and proved the build-env refactor is behaviorally equivalent to the prior code.
Verdict: correct, and the security goal is achieved. Executing the resolved JavaScript entrypoint via process.execPath with shell: false on all platforms eliminates the Windows cmd.exe injection vector while keeping --env a discrete argv value. I confirmed the two remaining shell: true sites (installDeps, React upgrade) only receive framework-generated package-manager args, never the attacker-controlled --env — the audit claim in the PR body holds.
Findings (minor / non-blocking)
1. Stale PR description. The body still states the fix is "rejecting null bytes and excessive lengths," but commit da865bc deliberately removed the 255-char limit. validateWranglerEnvName now only rejects null bytes. Worth updating the description so the listed behavior matches the merged code.
2. Resolution path — verified robust, just noting it. createRequire(path.join(root, 'package.json')).resolve('wrangler/package.json') fails when wrangler is not a direct dependency of the resolving package.json (reproduced from this repo's root). The _findInNodeModules fallback correctly recovers under pnpm's symlinked layout (verified by resolving from examples/hackernews), so real deploys resolve fine. The Yarn PnP case is covered only via an injected resolver in the test rather than a real PnP runtime — acceptable as a test seam, but real PnP returns a virtual package.json path that fs.readFileSync may not be able to read. Not blocking, but a candidate for a follow-up if PnP support is a hard requirement.
Confirmed equivalences
- Build-env logic (
deployEnv === 'production' && !options.env ? undefined : deployEnv) matches the oldoptions.env || (options.preview ? 'preview' : undefined)across all cases includingenv: 'production'andenv: ''. Build and deploy env stay in sync. - Dropping
previewfrom therunWranglerDeploycall is safe:previewis only consulted bybuildWranglerDeployArgswhenenvis undefined, and the new call already resolves preview→'preview'intoenv. - Env validation runs at the top of
deploy()before any filesystem/subprocess side effects, matching the regression test.
LGTM.
|
Review posted to PR #1946. ConclusionThe fix is correct and achieves its security goal. Switching to
Two minor, non-blocking findings posted: (1) the PR description's "excessive lengths" claim is stale (the length limit was removed in |
Summary
Fixes Windows command injection in
vinext deploy --envby removing the command shell from Wrangler execution.Vulnerability
On Windows, vinext resolved the package-manager
.cmdshim and called:With
shell: true, an attacker-controlled--envvalue was interpreted bycmd.exerather than remaining one argument.Previous POC
This could execute
whoamion the developer workstation or CI runner.Impact
A malicious repository command, copied deployment command, or attacker-controlled CI parameter could execute commands with the deploy process's privileges, including access to Cloudflare credentials and other CI secrets. This affects the build/deploy plane on Windows, not deployed Worker request handling.
Fix
binentry from its package manifest, including hoisted and Yarn Plug'n'Play resolution.process.execPathandshell: falseon every platform.--envas a discrete argument, preserving Wrangler-compatible names while rejecting null bytes and excessive lengths.shell: truecalls indeploy.ts; they only receive framework-generated package-manager dependency arguments, not--envor other direct deploy CLI strings.Regression coverage
runWranglerDeploy()usesprocess.execPathwithshell: false.binforms, and a Plug'n'Play-style resolver.Tests
Review
An independent Codex review agent reviewed the change three times. Initial findings around PnP resolution, environment compatibility, validation ordering, and subprocess-level reproduction were addressed. The final review reported no actionable findings.