CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
Official CWE-96 CWE context with Glexia analysis, remediation guidance, related CVEs, and ATT&CK context.
Glexia's Take
CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection') represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.
Executive Impact
- Confidentiality: Read Files or Directories,Read Application Data: The injected code could access restricted data / files.
- Access Control: Bypass Protection Mechanism: In some cases, injectable code controls authentication; this may lead to a remote vulnerability.
- Access Control: Gain Privileges or Assume Identity: Injected code can access resources that the attacker is directly prevented from accessing.
- Integrity,Confidentiality,Availability,Other: Execute Unauthorized Code or Commands: Code injection attacks can lead to loss of data integrity in nearly all cases as the control-plane data injected is always incidental to data recall or writing. Additionally, code injection can often result in the execution of arbitrary code.
- Non-Repudiation: Hide Activities: Often the actions performed by injected control code are unlogged.
Developer Pattern
CWE-96 is the kind of defect developers can usually prevent with explicit validation, safer framework defaults, and tests that exercise hostile input or unsafe state transitions.
Confidence
high confidence from CWE-96, 4.20.
Official CWE Definition
CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template.
Developer And Remediation Guidance
How teams prevent and detect this weakness
Causes
- This example attempts to write user messages to a message file and allow users to view them. While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:,which will decode to the following:,The programmer thought they were just including the contents of a regular data file, but PHP parsed it and executed the code. Now, this code is executed any time people view messages.,Notice that XSS (CWE-79) is also possible in this situation.
Remediation
- Implementation: [object Object]
- Implementation: Perform proper output validation and escaping to neutralize all code syntax from data written to code files.
Detection
- Automated Static Analysis: Automated 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.)
Mappings
Related CVEs, CWEs, and ATT&CK context
Related CWEs
ATT&CK Relevance
ATT&CK relevance is shown only when reviewed or responsibly inferred.