-
-
Notifications
You must be signed in to change notification settings - Fork 161
fix(child-process): validate null bytes at runtime boundaries #9568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ### Fixed | ||
|
|
||
| - **`child_process` now rejects embedded null bytes synchronously through both | ||
| direct imports and CommonJS-default namespaces (#9537).** The CJS method-call | ||
| dispatcher bypassed codegen-only validators, so `spawn`, `spawnSync`, | ||
| `execFile`, and related calls handed invalid file/argument strings to the OS | ||
| and later reported `UNKNOWN`. Runtime entry points now validate command, | ||
| file, and indexed argument strings before constructing a process, and | ||
| OS-facing `cwd`, `argv0`, `shell`, and environment strings use Node's exact | ||
| `ERR_INVALID_ARG_VALUE` message, including the property name and escaped | ||
| received value. |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // #9537 — every child_process spelling must reject embedded null bytes | ||
| // synchronously, before a command reaches the OS. The direct-import lowering | ||
| // already called setup validators, but CJS-default namespace dispatch skipped | ||
| // them and surfaced an asynchronous `UNKNOWN` spawn error instead. | ||
| // | ||
| // Byte-for-byte vs `node --experimental-strip-types`. | ||
| import * as direct from "node:child_process"; | ||
| import { createRequire } from "node:module"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const cjs: any = require("child_process"); | ||
|
|
||
| function probe(label: string, run: () => any): void { | ||
| try { | ||
| const value = run(); | ||
| // Keep the broken async-spawn path from turning the fixture's intended | ||
| // mismatch into an unhandled `error` event on a pre-fix binary. | ||
| if (value && typeof value.on === "function") value.on("error", () => {}); | ||
| console.log(label, "NO_THROW"); | ||
| } catch (e: any) { | ||
| console.log(label, "|", e.name, "|", e.code, "|", e.message); | ||
| } | ||
| } | ||
|
|
||
| // Existing direct-import path: pin the corrected Node message, including the | ||
| // argument name, original array index, escaped received value, class and code. | ||
| probe("direct spawn file", () => direct.spawn("/bin/tr\x00ue", [])); | ||
| probe("direct spawn args[1]", () => direct.spawn("/bin/true", ["ok", "a\x00b"])); | ||
| probe("direct spawn escaped received", () => | ||
| direct.spawn("/bin/true", ["a'\\\n\x00b"])); | ||
| probe("direct exec command", () => direct.exec("echo\x00x", () => {})); | ||
| probe("direct execFileSync args[1]", () => | ||
| direct.execFileSync("/bin/true", ["ok", "a\x00b"])); | ||
|
|
||
| // Regression path: fused method calls on require("child_process") route | ||
| // through the native-module dispatcher and then the runtime entry points. | ||
| probe("cjs spawn file", () => cjs.spawn("/bin/tr\x00ue", [])); | ||
| probe("cjs spawn args[1]", () => cjs.spawn("/bin/true", ["ok", "a\x00b"])); | ||
| probe("cjs spawnSync args[1]", () => cjs.spawnSync("/bin/true", ["ok", "a\x00b"])); | ||
| probe("cjs exec command", () => cjs.exec("echo\x00x", () => {})); | ||
| probe("cjs execSync command", () => cjs.execSync("echo\x00x")); | ||
| probe("cjs execFile args[1]", () => | ||
| cjs.execFile("/bin/true", ["ok", "a\x00b"], () => {})); | ||
| probe("cjs execFileSync file", () => cjs.execFileSync("/bin/tr\x00ue", [])); | ||
|
|
||
| // OS-facing option strings use Node's `property` wording. `cwd` is PathLike, | ||
| // so its expected-type clause additionally names Uint8Array and URL. | ||
| probe("cjs cwd", () => cjs.spawn("/bin/true", [], { cwd: "/tmp/a\x00b" })); | ||
| probe("cjs argv0", () => cjs.spawn("/bin/true", [], { argv0: "a\x00b" })); | ||
| probe("cjs shell", () => cjs.spawn("true", [], { shell: "/bin/s\x00h" })); | ||
| probe("cjs env value", () => cjs.spawn("/bin/true", [], { env: { A: "a\x00b" } })); | ||
| probe("cjs env undefined key", () => | ||
| cjs.spawn("/bin/true", [], { env: { ["A\x00B"]: undefined } })); | ||
|
|
||
| console.log("done"); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Use the canonical heap-address predicate.
Line 160 classifies a raw pointer with
is_above_handle_bandonly. Useis_plausible_heap_addrbefore re-boxing the pointer. This keeps raw-pointer routing consistent with the runtime address-class contract.Based on learnings: use
crate::value::addr_class::is_plausible_heap_addrfor raw-pointer classification and do not bypass it.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Learnings