Command Injection

Command Injection

Category: Injection

Severity: Critical


Command injection is an attack in which the goal is execution of arbitrary commands on the host operating system via a vulnerable application. Command injection attacks are possible when an application passes unsafe user supplied data (forms, cookies, HTTP headers etc.) to a system shell.


The attacker extends the default functionality of a vulnerable application, causing it to pass commands to the system shell, without needing to inject malicious code. In many cases, command injection gives the attacker greater control over the target system.


  • Set up input validation—to prevent attacks like XSS and SQL Injection.

  • Create a white list—of possible inputs, to ensure the system accepts only pre-approved inputs.

  • Use only secure APIs—when executing system commands such as execFile()

  • Use execFile() securely—prevent users from gaining control over the name of the program. You should also map user input to command arguments in a way that ensures user input does not pass as-is into program execution.

Last updated