As great as child processes are, they should be used with caution. Passing in user input must be sanitized, if not avoided at all.
The dangers of unsanitized input executing system-level logic are unlimited, reaching from remote code execution to the exposure of
sensitive system data and even data loss. A check list of preparations could look like this
const { exec } = require('child_process');
...
// as an example, take a script that takes two arguments, one of them is unsanitized user input
exec('"/path/to/test file/someScript.sh" --someOption ' + input);
// -> imagine what could happen if the user simply enters something like '&& rm -rf --no-preserve-root /'
// you'd be in for an unwanted surprise
From the Node.js child process documentation:
Never pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.
아무리 자식 프로세스가 성능이 좋더라도 주의해서 사용해야 한다. 사용자의 입력은 필터링이 되어있지 않다면 자식 프로세스의 사용을 금해야 한다.
시스템 수준의 로직을 실행하는 필터링 되지 않은 입력의 위험성은 무한하다. 이러한 위험성에는 원격 코드 실행, 민감한 시스템 데이터 노출 및 데이터 손실까지 있다. 이를 예방하기 위한 체크리스트는 다음과 같다.
const { exec } = require('child_process');
...
/// 두개의 인자를 갖는 스크립트를 사용하고 그중 하나는 필터링 되지 않은 사용자의 입력이다./
exec('"/path/to/test file/someScript.sh" --someOption ' + input);
/// -> 사용자가 단순히 '&& rm -rf --no-preserve-root /' 이렇게 입력하면 어떤 일이 일어날 수 있는지 생각해봐라/
/// 당신은 원치않는것을 경험할 것이다./
Node.js 자식 프로세스 문서로 부터:
/> 이 함수에 필터링 되지 않은 사용자의 입력을 전달하지 마라. 쉘 메타 문자를 포함하는 모든 입력은 임의의 명령 실행을 시작하는데 사용할 수 있다./