Repository navigation
fix: always quote the resolved next bin path - #3494
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: vtex/faststore/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. WalkthroughGenerated scripts quote resolved Next.js binary paths when invoking them through Node. ChangesNext.js path quoting
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The generated scripts now quote eligible Next paths and use the bare command for rejected paths. The additional path failure identified already existed before this change, so no PR-introduced merge risk remains. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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. |
lariciamota
left a comment
There was a problem hiding this comment.
Two updates before merge:
The title scope cli is not in the Lint PR allowlist (.github/workflows/pr.yml on dev). That check did not run on this commit; the next push will fail it. Recent CLI fixes omit the scope. fix: quote the next bin path when it contains spaces matches them.
The test plan does not reproduce the failure. A project directory that contains spaces still generates ../node_modules/next/dist/bin/next, because path.relative drops the shared prefix. The failing path is the one that climbs out of .faststore into the realpath of next, for example ../../../../john doe/Area de trabalho/.../next/dist/bin/next. Worth one sentence in "How to test it?" so the fix is verified against that path.
a3f8352 to
ee2c40e
Compare
DK Review — Audit SummaryVerdict:
Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other 2 findings below open 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 |
Double quotes stop the shell from splitting the path on spaces, but not from expanding $(...), backticks or $VAR; a " ends the quoting and cmd.exe still expands %VAR%. By returning undefined for those cases we fall back to the bare next
| */ | ||
| const next = nextBin ? `node ${nextBin}` : 'next' | ||
| const next = nextBin ? `node "${nextBin}"` : 'next' | ||
|
|
There was a problem hiding this comment.
[Functional.Check] 🟡 RESTRICT
buildFaststorePackageJson interpolates nextBin into a shell command string (node "${nextBin}") without validating it itself. The only guard against ", $, backtick, or % in the path is the UNQUOTABLE_CHARS check inside the separate relativeNextBin function. Any caller that passes a raw resolved path to buildFaststorePackageJson without first routing it through relativeNextBin (the test file itself does exactly this) reintroduces the shell/command injection this PR aims to close.
Action: Validate for unquotable characters inside buildFaststorePackageJson itself before interpolating, or encode the invariant in the type system (e.g. a branded SanitizedRelativePath type only producible by relativeNextBin) so safety doesn't depend on every caller remembering to pre-sanitize.
To dismiss: reply /dk-review dismiss [reason] under this comment
There was a problem hiding this comment.
I'll take this in a follow-up PR. The production caller already goes through relativeNextBin, so the generated script is covered. Moving the check into buildFaststorePackageJson keeps a future caller from skipping it.
dd52ffb to
3b5a237
Compare
|
|
||
| return relative && !path.isAbsolute(relative) ? relative : undefined | ||
| return relative && | ||
| !path.isAbsolute(relative) && |
There was a problem hiding this comment.
[Functional.Check] 🟡 RESTRICT
relativeNextBin only rejects relative paths containing '"', '$', '', or '%', but does not guard against a resolved path whose first character is '-'. That value is spliced into node "${nextBin}" build --webpack; shell quoting only affects word-splitting, not how node's own argv parser treats a leading-dash token as a CLI flag. A resolved relative path like -e/dist/bin/nextturns the generated script intonode "-e/dist/bin/next" build --webpack, which node parses as the -e` eval flag with the rest of the quoted string as the code argument, and 'build' becomes the next argv entry — breaking the build instead of invoking Next. This is the same threat model the PR is hardening (an oddly-named or attacker-influenced directory reaching the generated script unescaped), just via argument injection rather than shell metacharacter injection, and it isn't covered by UNQUOTABLE_CHARS or the new test cases.
Action: Also fall back to undefined when the first segment of the relative path starts with '-', or prefix the path with './' before quoting so it can never be parsed as a flag.
Source: packages/cli/src/utils/generate.ts lines 111-144 (UNQUOTABLE_CHARS / relativeNextBin)
To dismiss: reply /dk-review dismiss [reason] under this comment
There was a problem hiding this comment.
Not needed here. A relative path that leaves .faststore starts with .., and Node only treats the argument as a flag when the argument itself starts with -. A - later in the path is part of the file name.
|
…3503) ## Summary - `buildFaststorePackageJson` now applies the same guard as `relativeNextBin` before writing the Next script. A path containing `"`, `$`, a backtick, or `%` falls back to the bare `next` command instead of being interpolated into `node "<path>"`. - This covers a caller that passes `nextBin` without going through `relativeNextBin`. The production path already did; the check now lives where the shell string is written. - Follow-up to #3494. ## Test plan - [ ] `cd packages/cli && pnpm vitest run src/utils/generate.test.ts` - [ ] Confirm a path with a space is still quoted (`node "<path>"`) - [ ] Confirm a path with `"`, `$`, a backtick, or `%` produces `next build --webpack` (and the same for `serve`, `dev`, and `dev-only`) Made with [Cursor](https://cursor.com) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved command generation for projects with Next.js executable paths containing special characters. In these cases, generated scripts use the standard `next` command instead, avoiding shell expansion issues. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Cursor <[email protected]>

0 New Issues
0 Fixed Issues
0 Accepted Issues
What's the purpose of this pull request?
The CLI writes the
nextscripts of.faststore/package.json(build,serve,dev,dev-only) asnode <nextBin> ..., wherenextBinis the Next binary resolved from@faststore/core, relative to.faststore.That binary is resolved through its realpath. When
nextis a symlink target elsewhere on disk, the relative path climbs out of.faststoreand keeps every directory it does not share with it, e.g.../../../../john doe/Area de trabalho/repo/node_modules/next/dist/bin/next. Unquoted, the shell splits that path on each space,nodereceives only the first piece, and the script fails withCannot find module.How it works?
The resolved path is now always wrapped in double quotes:
node "<nextBin>" .... Double quotes are the quoting bothshandcmd.exeunderstand; single quotes or a backslash escape would break the script on Windows. This matches how the absolute-path version of this script was written before 4.8.0.The comment above it was rewritten as well: it claimed the relative path only spans
node_modulessegments, which is the assumption this bug disproves.Tests:
nextBinthe way the CLI does, from a.faststoreand a Next binary that do not share the spaced directory, and asserts all four scripts use the quoted path.How to test it?
A store directory that merely contains spaces does not reproduce the bug:
path.relativedrops the directory.faststoreshares withnext, so the script staysnode "../node_modules/next/dist/bin/next". To reproduce it,nexthas to resolve to a directory outside the store whose path has a space:nextbinary resolves, through a symlink, to a path such as/Users/john doe/Area de trabalho/repo/node_modules/nextfaststore generateand check that thebuild,serve,devanddev-onlyscripts in.faststore/package.jsonarenode "<path containing the spaces>" ...yarn dev/yarn buildand confirm Next starts, where the previous version failed withCannot find modulecd packages/cli && pnpm vitest run src/utils/generate.test.tsStarters Deploy Preview
References
Checklist
You may erase this after checking them all 😉
PR Title and Commit Messages
feat,fix,chore,docs,style,refactor,ciandtestPR Description
breaking change,bug,contributing,performance,documentation..Dependencies
pnpm-lock.yamlfile when there were changes to the packagesDocumentation
@Mariana-Caetanoto review and update (Or submit a doc request)Summary by CodeRabbit
Summary by CodeRabbit
.faststore.nextcommand.