LIVE NEWSROOM · --:-- · May 24, 2026
A LIBRARY FOR SECURITY RESEARCHERS

CWE WEAKNESSES  /  CWE-78

CWE-78

Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')

Base EXPLOIT LIKELIHOOD: HIGH

What it is

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 [HOSTNAM

Impact

Confidentiality, Integrity, Availability, Non-RepudiationExecute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart, Read Files or Directories, Modify Files or Directories, Read Application Data, Modify Application Data, Hide Activities

Mitigations

  • [Architecture and Design] If at all possible, use library calls rather than external processes to recreate the desired functionality.
  • [Architecture and Design, Operation]Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software.OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. Fo
  • [Architecture and Design] 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.
  • [Architecture and Design] For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
  • [Architecture and Design]Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.For example, consider using the ESAPI Encoding control [REF-45] or a similar tool, library, or framework. These will help the programmer encode outputs in a manner less prone to error.
  • [Implementation] While it is risky to use dynamically-generated query strings, code, or commands that mix control and data together, sometimes it may be unavoidable. Properly quote arguments and escape any special characters within those arguments. The most conservative approach is to escape or filter all characters that do not pass an extremely strict allowlist (such as everything that is not alphanumeric or whit
  • [Implementation] 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.
  • [Architecture and Design]If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated.Some languages offer multiple functions that can be used to invoke commands. Where p

Real-world CVE examples

  • CVE-2024-53899 — Virtual environment builder does not correctly quote "magic" template strings, allowing OS command injection using a directory whose name contains shell metacha
  • CVE-2025-44844 — file upload functionality in wireless access point allows OS command injection via shell metacharacters through the file name in a Content-Disposition header
  • CVE-2024-6091 — Chain: AI agent platform does not restrict pathnames containing internal "/./" sequences (CWE-55), leading to an incomplete denylist (CWE-184) that does not pre
  • CVE-2024-41316 — Lua application in network device allows OS command injection into os.execute()
  • CVE-2024-44335 — Chain: filter only checks for some shell-injection characters (CWE-184), enabling OS command injection (CWE-78)
  • CVE-2024-52803 — Platform for handling LLMs has OS command injection during training due to insecure use of the "Popen" function
  • CVE-2020-10987 — OS command injection in Wi-Fi router, as exploited in the wild per CISA KEV.
  • CVE-2020-10221 — Template functionality in network configuration management tool allows OS command injection, as exploited in the wild per CISA KEV.
  • CVE-2020-9054 — Chain: improper input validation (CWE-20) in username parameter, leading to OS command injection (CWE-78), as exploited in the wild per CISA KEV.
  • CVE-1999-0067 — Canonical example of OS command injection. CGI program does not neutralize "|" metacharacter when invoking a phonebook program.
  • CVE-2001-1246 — Language interpreter's mail function accepts another argument that is concatenated to a string used in a dangerous popen() call. Since there is no neutralizatio
  • CVE-2002-0061 — Web server allows command execution using "|" (pipe) character.

Related weaknesses

Test & detect

Browse all common weaknesses, check related exploited CVEs, or map to ATT&CK techniques.

Source: MITRE CWE. View on cwe.mitre.org →

Scroll to Top