CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')

What is CWE-77?

The product builds part or all of a command from input influenced by an external source, but fails to neutralize, or incorrectly neutralizes, special elements that can alter the intended command before it is processed by a downstream component.

Data statistics

OWASP TOP 10:2025 RANK5 — A05:2025 — Injection
RELATED CVES (365 DAYS)515
ABSTRACTIONClass
LIKELIHOOD OF EXPLOITHigh

Vulnerabilities mapped to CWE-77

515 vulnerabilities210.2% increase year over year

Vulnerabilities in CISA KEV for CWE-77

2 vulnerabilitiesNo change year over year

Official definition

ByMitre CWE

The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.

Many protocols and products have their own custom command language. While OS or shell command strings are frequently discovered and targeted, developers may not realize that these other command languages might also be vulnerable to attacks.

Detailed description

This weakness occurs when untrusted data is incorporated into a command string that the application executes or passes to another command interpreter. An injected delimiter or other command-language syntax can terminate the intended command and introduce a new command or operation. The issue is not limited to operating system shells: custom languages used by protocols, utilities, image processors, configuration formats, and other products can also interpret attacker-controlled syntax. It is distinct from the broader command-language injection category and is often, though not always, associated with OS command injection.

Characteristics

The weakness is language and platform agnostic and can arise during implementation when data from an untrusted source becomes part of a command executed by the application. It commonly involves a source-to-sink data flow in which externally influenced input reaches a command interpreter or another component that parses command syntax. The relevant syntax may be shell metacharacters, script syntax, optional arguments, configuration commands, or constructs from a product-specific command language. The official record lists AI/ML as an applicable technology, but does not establish prevalence.

Common consequences

A successful injection can allow an attacker to execute unauthorized code or commands, giving the attacker capabilities or privileges that were not intended. The resulting impact can affect confidentiality, integrity, and availability, depending on the commands accepted by the downstream component and the privileges of the executing process.

ImpactScopeExplanation
Execute Unauthorized Code or CommandsIntegrity, Confidentiality, AvailabilityIf a malicious user injects a character (such as a semi-colon) that delimits the end of one command and the beginning of another, it may be possible to then insert an entirely new and unrelated command that was not intended to be executed. This gives an attacker a privilege or capability that they would not otherwise have.

Risk mitigations

Architecture and design: Prefer library calls over external processes when they can provide the required functionality. Implementation: Keep externally invoked commands statically defined whenever possible. Treat all input as malicious and apply strict allowlist, or accept-known-good, validation covering length, type, allowed values, missing or extra fields, syntax, consistency, and business rules. Do not rely only on denylists or searches for known malicious patterns; denylists can still help detect suspected attacks or reject clearly malformed input. Runtime and configuration: Enforce an allowlist of sanctioned commands at runtime and assign permissions that prevent users from accessing or opening privileged files.

  1. Architecture and DesignIf at all possible, use library calls rather than external processes to recreate the desired functionality.
  2. ImplementationIf possible, ensure that all external commands called from the program are statically created.
  3. Input Validation · ImplementationAssume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
  4. OperationRun time: Run time policy enforcement may be used in an allowlist fashion to prevent use of any non-sanctioned commands.
  5. System ConfigurationAssign permissions that prevent the user from accessing/opening privileged files.

Detection methods

Automated static analysis, commonly called Static Application Security Testing (SAST), can identify some instances without executing the program. It typically models data flow and control flow, then searches for paths from input sources to sinks where data interacts with external components or lower layers such as the operating system. This approach has high stated effectiveness, but its coverage is limited to weaknesses that can be recognized from the analyzed code or compiled representation and modeled source-to-sink patterns.

MethodApproachEffectiveness
Automated Static AnalysisAutomated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)High

Representative vulnerabilities

The official record provides these representative examples, not an exhaustive list:

  • CVE-2022-1509, CVE-2021-41282, and CVE-2019-13398: injection of sed script syntax.
  • CVE-2024-5184: direct prompt injection in an API service using a large generative AI model, allowing leakage of hard-coded system prompts or execution of other prompts.
  • CVE-2020-11698: injection of SNMP commands into a configuration file in an anti-spam product.
  • CVE-2019-12921: command injection in the Magick Vector Graphics (MVG) language used by an image program.
  • CVE-2022-36069: injection of optional arguments beginning with a dash in a Python dependency management tool, potentially enabling code execution, despite avoidance of OS command injection when generating Git commands.
  • CVE-1999-0067: failure to neutralize the | metacharacter when a CGI program invoked a phonebook program.
  • CVE-2020-9054: improper validation of a username parameter leading to OS command injection, with exploitation in the wild noted in the record.
Sources (5)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.

Explore CyStack VulnScan