Repository navigation
fix: refuse an unquotable next path inside the package.json builder - #3503
Conversation
The shell string is written here, so a caller that skips relativeNextBin could still interpolate a quote, a dollar sign, a backtick, or a percent sign. Co-authored-by: Cursor <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: vtex/faststore/.coderabbit.yaml Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. WalkthroughThe CLI now uses an embedded Next executable path only when it contains no double quote, dollar sign, backtick, or percent sign. Otherwise, generated scripts use the bare ChangesNext executable path handling
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to Unsafe paths now avoid shell interpolation, while production behavior remains unchanged. No PR-specific merge blocker is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
|
| * backticks, a `"` ends the quoting, and `cmd.exe` expands `%VAR%`. | ||
| */ | ||
| const UNQUOTABLE_CHARS = /["$`%]/ | ||
|
|
There was a problem hiding this comment.
[Functional.Check] 🟡 RESTRICT
UNQUOTABLE_CHARS only screens for ", $, `, and %, but npm/pnpm run package.json scripts on Windows via cmd.exe /c, where double quotes do not reliably neutralise &, |, <, >, ^, (, or ). Given the surrounding comment's own threat model (a resolved symlink's realpath can climb outside .faststore into attacker-influenced directory names), a path containing one of these characters can still break out of the quoted node "..." argument on Windows and inject a command, defeating the guard this diff adds.
Action: Extend UNQUOTABLE_CHARS to also match &|<>^(), and add it.each cases in generate.test.ts for those characters mirroring the existing quote/$/backtick/% cases. Consider citing Node's cmd.exe quoting advisory (CVE-2024-27980) in the comment as rationale for the fuller character set.
To dismiss: reply /dk-review dismiss [reason] under this comment
There was a problem hiding this comment.
Not changing this set. Inside double quotes, &, |, <, >, ^, ( and ) are literal in both sh and cmd.exe. The characters that still expand or end the quoting are the ones already rejected: ", $, a backtick, and %.
Rejecting ( and ) would also drop a normal Windows path such as Program Files (x86) and fall back to the bare next command. CVE-2024-27980 is about Node escaping arguments when it spawns a .bat or .cmd, not about a quoted path in a package.json script.
| ['a double quote', '../node_modules/my "next"/dist/bin/next'], | ||
| ['a dollar sign', '../node_modules/$next/dist/bin/next'], | ||
| ['a backtick', '../node_modules/`next`/dist/bin/next'], | ||
| ['a percent sign', '../node_modules/%next%/dist/bin/next'], |
There was a problem hiding this comment.
[Functional.Check] 🟡 RESTRICT
The new it.each cases only verify the shell-injection fallback for four characters (", $, `, %). Other classic shell metacharacters that could break out of the generated script string (e.g. ;, |, &, newline, single quote ', backslash ) are not covered, so the guard's actual robustness against command injection remains unverified.
Action: Add cases for ';', '|', '&', newline, "'", and '' to the it.each table so the fallback behavior is verified against the full set of shell-significant characters, not just a subset.
To dismiss: reply /dk-review dismiss [reason] under this comment
There was a problem hiding this comment.
Not adding these as fallback cases. ;, |, &, ', and \ stay literal inside the double quotes this script already uses, so they should remain part of the quoted path. Asserting that they fall back to the bare next command would lock in the wrong behavior.
The it.each covers the characters the quotes do not neutralise.
DK Review — Audit SummaryVerdict:
Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other finding below opens no review thread. Scenarios evaluated: feature-flags, general-review, quality-ratchet 📋 Findings (3)RESTRICT
SUGGEST
DK Review v1.0.0 | To dismiss a finding: reply |

0 New Issues
0 Fixed Issues
0 Accepted Issues
Summary
buildFaststorePackageJsonnow applies the same guard asrelativeNextBinbefore writing the Next script. A path containing",$, a backtick, or%falls back to the barenextcommand instead of being interpolated intonode "<path>".nextBinwithout going throughrelativeNextBin. The production path already did; the check now lives where the shell string is written.Test plan
cd packages/cli && pnpm vitest run src/utils/generate.test.tsnode "<path>")",$, a backtick, or%producesnext build --webpack(and the same forserve,dev, anddev-only)Made with Cursor
Summary by CodeRabbit
nextcommand instead, avoiding shell expansion issues.