Repository navigation
fix(win32): probe .cmd/.bat runtime shims via cmd.exe to avoid spawn EINVAL - #505
Merged
Merged
Conversation
…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
Owner
|
Thank you for contributing, @ahkurdev! Great catch on the Node CVE-2024-27980 batch-spawn block — routing I've pushed a small follow-up to your branch (platform threading through |
This was referenced Oct 5, 2026
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]>
2 tasks done
22 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On Windows,
rea doctorfails 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/.batfiles without a shell and throwsEINVAL. On Windows thenpmandnpxPATH shims are.CMDfiles, so every runtime-toolchain probe of them fails withruntime_spawn_failed, and on some environments (e.g. when a batch shim is probed first) the whole doctor run reportsspawn EINVAL.Reproduction: on a healthy Windows x64 host with Node >= 20.12, run
rea doctor—node-toolchainsreports the npm/npx.CMDshims as failed probes.Fix
Route batch-file candidates through
cmd.exe /d /s /c:windowsBatchCommand()detects.cmd/.batcandidates on win32 and builds acmd.exeinvocation with the whole command line as a single quoted argumentwindowsVerbatimArguments: trueprevents Node from re-quoting, so paths with spaces surviveTesting
RuntimeExecutableDiagnostics.win32.test.tsexercises real probes through the patchedexecuteVersionand asserts noruntime_spawn_failed(EINVAL) — 2 passedDoctor.runtimeExecutables.test.ts— passedtsc -p tsconfig.build.json --noEmit— cleanValidated end-to-end on Windows 11 x64, Node 26.7.0: after the same patch (applied to the installed package)
rea doctorreportsnode,node-toolchains, andhostas healthy instead ofspawn EINVAL/ failed.CMDprobes.