Repository navigation
fix: harden runWrangler against shell injection and silence DEP0190 #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kirkouimet
wants to merge
7
commits into
opennextjs:main
Choose a base branch
from
kirkouimet:fix-runwrangler-shell-injection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
726e3ef
fix: harden runWrangler against shell injection and silence DEP0190
kirkouimet 5df6c61
fix: split multi-word args at every runWrangler call site
kirkouimet 227371e
fix: address review feedback on runWrangler shell injection PR
kirkouimet 9f39728
fix: address review feedback round 2 from @vicb and @james-elicx
kirkouimet 382e5d1
fix: silence DEP0190 on Windows too via cmd.exe /c invocation
kirkouimet 229c45f
fix: correct quoteShellMeta Windows escaping algorithm
kirkouimet 5a5a768
docs: address review feedback on comments
kirkouimet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
docs: address review feedback on comments
Per @vicb's review: - helpers.ts: rewrite quoteShellMeta docstring so it describes both the Windows and POSIX branches with equal weight, rather than treating POSIX as a footnote. The function works on both platforms. - helpers.ts: simplify the inner POSIX comment to "POSIX shell quoting" per the suggestion. - run-wrangler.ts: hoist the shell:false / DEP0190 explanation to the top-level comment block so it covers both branches, then describe the POSIX path and the Windows path in turn. Drop the now-redundant inner comment in the POSIX spawn call. - run-wrangler.ts: restore the stdio explanatory comment that was lost when stdio was hoisted to a const in an earlier refactor. No behavioral changes.
- Loading branch information
commit 5a5a7682a3d2cc444c6c7efc2348cc6aa19b2e43
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,9 @@ export function runWrangler( | |
| ]), | ||
| ]; | ||
|
|
||
| // Always pipe stderr so that we can capture it for inspection. | ||
| // Keep stdin and stdout as "inherit" when not piping logs to maintain TTY detection | ||
| // (wrangler checks `process.stdin.isTTY && process.stdout.isTTY` for interactive mode). | ||
| const stdio: ("inherit" | "ignore" | "pipe")[] = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please re-add the former comment on this |
||
| shouldPipeLogs || noLogs ? ["ignore", "pipe", "pipe"] : ["inherit", "inherit", "pipe"]; | ||
|
|
||
|
|
@@ -124,16 +127,18 @@ export function runWrangler( | |
| CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: "false", | ||
| }; | ||
|
|
||
| // On Windows the package manager binary is typically a `.cmd` shim. Per Node.js docs | ||
| // https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows the | ||
| // recommended way to invoke a `.cmd`/`.bat` is to spawn `cmd.exe` directly with `/c`, | ||
| // rather than relying on `shell: true` (which emits DEP0190 and would re-tokenize values). | ||
| // We pre-escape every token with `quoteShellMeta` and pass the joined command line as a | ||
| // single quoted string with `windowsVerbatimArguments: true` so Node does not re-escape it. | ||
| // This mirrors how `cross-spawn` handles non-`.exe` commands on Windows. | ||
| // We use `shell: false` everywhere to avoid DEP0190. | ||
| // See https://nodejs.org/api/deprecations.html#dep0190-passing-args-to-nodechild-process-execfilespawn-with-shell-option | ||
| // | ||
| // On POSIX we spawn the package manager directly with `shell: false`, which avoids DEP0190 | ||
| // and lets each value be passed verbatim as its own argv entry. | ||
| // On POSIX we can spawn the package manager binary directly: each value is passed verbatim | ||
| // as its own argv entry. | ||
| // | ||
| // On Windows the package manager is typically a `.cmd` shim. Per Node.js docs | ||
| // (https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows) the | ||
| // recommended way to invoke a `.cmd`/`.bat` without `shell: true` is to spawn `cmd.exe` | ||
| // directly with `/c`. We pre-escape every token with `quoteShellMeta` and pass the joined | ||
| // command line as a single quoted string with `windowsVerbatimArguments: true` so Node | ||
| // does not re-escape it. This mirrors how `cross-spawn` handles non-`.exe` commands. | ||
| const result = isWin | ||
| ? spawnSync( | ||
| "cmd.exe", | ||
|
|
@@ -151,8 +156,6 @@ export function runWrangler( | |
| } | ||
| ) | ||
| : spawnSync(options.packager, packagerArgs, { | ||
| // Setting `shell` to `false` to avoid DEP0190. | ||
| // See https://nodejs.org/api/deprecations.html#dep0190-passing-args-to-nodechild-process-execfilespawn-with-shell-option | ||
| shell: false, | ||
| stdio, | ||
| env, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Uh oh!
There was an error while loading. Please reload this page.