What is CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+
CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage. There are at least two subtypes of OS command injection: The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing. The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line. From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
Is CWE-78 in the CWE Top 25 Most Dangerous Software Weaknesses?+
Yes. CWE-78 ranked #8 in the CWE Top 25 for 2024, associated with 415 CVEs that year. The CWE Top 25 highlights the most common and impactful software weaknesses based on real-world vulnerability data.
What are the security consequences of Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+
If exploited, CWE-78 (Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) it can compromise Confidentiality, Integrity, Availability and Non-Repudiation, leading to outcomes such as Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart, Read Files or Directories, Modify Files or Directories, Read Application Data and Modify Application Data.
How do you prevent or mitigate Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+
Recommended mitigations for CWE-78 include: If at all possible, use library calls rather than external processes to recreate the desired functionality. For any data that will be used to generate a command to be executed, keep as much of that data out of external control as possible. For example, in web applications, this may require storing the data locally in the session's state instead of sending it out to the client in a hidden form field. If the program to be executed allows arguments to be specified within an input file or from standard input, then consider using that mode to pass arguments instead of the command line.
How is Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') detected?+
CWE-78 can be detected using Automated Static Analysis - Binary or Bytecode, Dynamic Analysis with Automated Results Interpretation, Dynamic Analysis with Manual Results Interpretation, Manual Static Analysis - Source Code, Automated Static Analysis - Source Code and Architecture or Design Review. Combining automated tooling with manual review typically yields the best coverage.
Which programming languages are affected by Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+
CWE-78 commonly affects Not Language-Specific. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
What are real-world examples of Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+
MITRE documents real CVEs mapped to CWE-78, including CVE-2024-53899, CVE-2025-44844, CVE-2024-6091, CVE-2024-41316 and CVE-2024-44335. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.
What is the difference between a CWE and a CVE?+
A CWE (Common Weakness Enumeration) like CWE-78 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.