Closed
Description
Version
v18.9.1
Platform
Linux tsc-ubuntu2204 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
child_process
What steps will reproduce the bug?
//// spawner.js
const {spawn} = require('child_process');
const myArgs = ['dump.js','AAA','BBB\0XXX', 'CCC'];
console.log('spawner.js:', myArgs);
const childProcess = spawn('node', myArgs);
childProcess.stdout.on('data', (chunk) => {
console.log(chunk.toString());
});
//// dump.js
console.log('dump.js:', process.argv);
$ node spawner.js
spawner.js: [ 'dump.js', 'AAA', 'BBB\x00XXX', 'CCC' ]
dump.js: [ '/usr/local/bin/node', '/tmp/dump.js', 'AAA', 'BBB', 'CCC' ]
How often does it reproduce? Is there a required condition?
No particular condition required.
What is the expected behavior?
Node.js should raise error when invalid args (containing null byte) are given.
What do you see instead?
No error raised. Null byte and subsequent bytes are silently truncated.
Additional information
Other languages below have null byte checking and raise error in the same situation.
Java: java.io.IOException: invalid null character in command
PHP: Uncaught ValueError: Command array element 4 contains a null byte
Python: ValueError: embedded null byte
Ruby: ArgumentError (string contains null byte)
IMO raising error is safer to avoid null byte injection.