Skip to content

fix(win32): probe .cmd/.bat runtime shims via cmd.exe to avoid spawn EINVAL - #505

Merged
morluto merged 2 commits into
morluto:mainfrom
ahkurdev:fix/win32-cmd-spawn-einval
Oct 5, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
ahkurdev:fix/win32-cmd-spawn-einval

Conversation

@ahkurdev

@ahkurdev ahkurdev commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Problem

On Windows, rea doctor fails with { code: "UNKNOWN", message: "spawn EINVAL" } on Node >= 18.20 (verified on Node 26.7.0).

Node's CVE-2024-27980 mitigation blocks spawning .cmd/.bat files without a shell and throws EINVAL. On Windows the npm and npx PATH shims are .CMD files, so every runtime-toolchain probe of them fails with runtime_spawn_failed, and on some environments (e.g. when a batch shim is probed first) the whole doctor run reports spawn EINVAL.

Reproduction: on a healthy Windows x64 host with Node >= 20.12, run rea doctor — node-toolchains reports the npm/npx .CMD shims as failed probes.

Fix

Route batch-file candidates through cmd.exe /d /s /c:

  • windowsBatchCommand() detects .cmd/.bat candidates on win32 and builds a cmd.exe invocation with the whole command line as a single quoted argument
  • windowsVerbatimArguments: true prevents Node from re-quoting, so paths with spaces survive
  • non-batch paths keep the exact previous spawn behavior

Testing

  • New test RuntimeExecutableDiagnostics.win32.test.ts exercises real probes through the patched executeVersion and asserts no runtime_spawn_failed (EINVAL) — 2 passed
  • Existing Doctor.runtimeExecutables.test.ts — passed
  • tsc -p tsconfig.build.json --noEmit — clean
  • Prettier — formatted

Validated end-to-end on Windows 11 x64, Node 26.7.0: after the same patch (applied to the installed package) rea doctor reports node, node-toolchains, and host as healthy instead of spawn EINVAL / failed .CMD probes.

ahkurdev and others added 2 commits October 5, 2026 08:53
…EINVAL

Node >= 18.20 refuses to spawn .cmd/.bat files without a shell
(CVE-2024-27980 mitigation) and throws spawn EINVAL. On Windows, the
npm and npx PATH shims are .CMD files, so doctor's runtime toolchain
probes always failed even on a healthy install.

Route batch-file candidates through cmd.exe /d /s /c with the command
line as a single quoted argument and windowsVerbatimArguments.
…oting

- windowsBatchCommand takes platform/systemRoot params instead of reading
  process.platform directly, so it is unit-testable off Windows
- double embedded quotes in the cmd.exe /c string to block breakout
- replace spawn-based win32 tests with pure helper units plus a
  win32-only temp .bat probe
@morluto

morluto commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Thank you for contributing, @ahkurdev! Great catch on the Node CVE-2024-27980 batch-spawn block — routing .cmd/.bat probes through cmd.exe is exactly the right fix.

I've pushed a small follow-up to your branch (platform threading through probeCandidate/executeVersion, quote-doubling in the /c string, and pure unit tests for windowsBatchCommand plus a win32-only live probe) so the new tests also pass on non-Windows CI. Let me know if you'd like anything adjusted — otherwise this will merge once checks are green. Thanks again for the first contribution! 🙏

@ahkurdev

ahkurdev commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the follow-up, @morluto ! Really appreciate it. 🙏

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…EINVAL (morluto#505)

* fix(win32): probe .cmd/.bat runtime shims via cmd.exe to avoid spawn EINVAL

Node >= 18.20 refuses to spawn .cmd/.bat files without a shell
(CVE-2024-27980 mitigation) and throws spawn EINVAL. On Windows, the
npm and npx PATH shims are .CMD files, so doctor's runtime toolchain
probes always failed even on a healthy install.

Route batch-file candidates through cmd.exe /d /s /c with the command
line as a single quoted argument and windowsVerbatimArguments.

* fix(win32): thread platform through version probe and harden batch quoting

- windowsBatchCommand takes platform/systemRoot params instead of reading
  process.platform directly, so it is unit-testable off Windows
- double embedded quotes in the cmd.exe /c string to block breakout
- replace spawn-based win32 tests with pure helper units plus a
  win32-only temp .bat probe

---------

Co-authored-by: morluto <[email protected]>
@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants