Skip to content

fix: refuse an unquotable next path inside the package.json builder - #3503

Merged
lariciamota merged 1 commit into
devfrom
fix/guard-next-bin-script
Sep 28, 2026
Merged

lariciamota merged 1 commit into
devfrom
fix/guard-next-bin-script

Conversation

@lariciamota

@lariciamota lariciamota commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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 fix: always quote the resolved next bin path #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

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.

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]>
@lariciamota
lariciamota requested a review from a team as a code owner September 28, 2026 20:17
@lariciamota
lariciamota requested review from gabpaladino and renatamottam and removed request for a team September 28, 2026 20:17
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository: vtex/faststore/.coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: e4b29697-683e-4dd7-9637-d43c8ade8910

📥 Commits

Reviewing files that changed from the base of the PR and between 407a05a and 9badd7a.

📒 Files selected for processing (2)
  • packages/cli/src/utils/generate.test.ts
  • packages/cli/src/utils/generate.ts

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.


Walkthrough

The 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 next command. Tests cover the fallback for each character.

Changes

Next executable path handling

Layer / File(s) Summary
Path guard, script generation, and tests
packages/cli/src/utils/generate.ts, packages/cli/src/utils/generate.test.ts
The generator checks executable paths for unsafe characters and falls back to bare next when needed. Parameterized tests cover generated build, serve, dev, and dev-only scripts.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 9badd

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: rejecting unsafe Next.js paths in the package.json builder.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@codesandbox-ci

Copy link
Copy Markdown

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.

@sonar-workflows

Copy link
Copy Markdown

* backticks, a `"` ends the quoting, and `cmd.exe` expands `%VAR%`.
*/
const UNQUOTABLE_CHARS = /["$`%]/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-pr-review

dk-pr-review Bot commented Sep 28, 2026

Copy link
Copy Markdown

DK Review — Audit Summary

Verdict: ⚠️ RESTRICTED

Severity Count
BLOCK 0
RESTRICT 2
SUGGEST 1

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
Scenarios skipped: dependency-governance (no matching files), pipeline-config (no matching files), agent-skills-review (no matching files)


📋 Findings (3)

RESTRICT

  1. [Functional.Check] packages/cli/src/utils/generate.ts:60 — 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.
    → 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.
  2. [Functional.Check] packages/cli/src/utils/generate.test.ts:148 — 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.
    → 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.

SUGGEST

  1. [Evolvability.Textual] packages/cli/src/utils/generate.test.ts:140 — The comment explains the security rationale of the production guard in buildFaststorePackageJson/relativeNextBin (why the fallback exists), but it lives only in the test file. If the guard in generate.ts changes, this explanatory context won't be next to the code it describes and can silently go stale.
    → Move the 'why' explanation to a comment next to the actual guard/fallback logic in generate.ts, and keep only a brief pointer comment in the test.

DK Review v1.0.0 | To dismiss a finding: reply /dk-review dismiss [reason] under its comment

@lariciamota
lariciamota merged commit da85b46 into dev Sep 28, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants