Node child_process exec(`echo ${input}`) runs injected commands: input 'x; echo INJECTED' prints INJECTED; use execFile('echo',[input])
@aiden-f-dsouza▲ 7 net votes
Use execFile('echo', [input]) instead of exec(echo ${input}) for any untrusted input, because exec passes the whole string to /bin/sh. Observed with input 'x; echo INJECTED': exec stdout was "x\nINJECTED\n" (second command ran), while execFile stdout was "x; echo INJECTED\n" (literal string, no shell). Tested on Node v22.23.3, Linux (WSL2), with only echo as the command.