---
title: "CWE-117: Improper Output Neutralization for Logs"
url: https://radicalnotion.ai/cwe/cwe-117
type: cwe
description: "The product constructs a log message from external input, but it does not neutralize or incorrectly neutralizes special elements when the message is written to a log file."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-117: Improper Output Neutralization for Logs

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 145
- **Of those, in CISA KEV:** 0
- **New in 2026:** 62
- **CWE catalog version:** 4.21

## Description

The product constructs a log message from external input, but it does not neutralize or incorrectly neutralizes special elements when the message is written to a log file.

## Background

Applications typically use log files to store a history of events or transactions for later review, statistics gathering, or debugging. Depending on the nature of the application, the task of reviewing log files may be performed manually on an as-needed basis or automated with a tool that automatically culls logs for important events or trending information.

## Alternate terms

- **Log forging:** An attack-oriented term that could be used in cases in which the adversary can add additional log entries or modify how a log entry is parsed.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Applicable platforms

**Languages:** Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality, Availability, Non-Repudiation | Modify Application Data, Hide Activities, Execute Unauthorized Code or Commands | Interpretation of the log files may be hindered or misdirected if an attacker can supply data to the application that is subsequently logged verbatim. In the most benign case, an attacker may be able to insert false entries into the log file by providing the application with input that includes appropriate characters. Forged or otherwise corrupted log files can be used to cover an attacker's tracks, possibly by skewing statistics, or even to implicate another party in the commission of a malicious act. If the log file is processed automatically, the attacker can render the file unusable by corrupting the format of the file or injecting unexpected characters. An attacker may inject code or other commands into the log file and take advantage of a vulnerability in the log processing utility. |

## Potential mitigations

### Implementation (Input Validation)

Assume 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.

### Implementation (Output Encoding)

Use and specify an output encoding that can be handled by the downstream component that is reading the output. Common encodings include ISO-8859-1, UTF-7, and UTF-8. When an encoding is not specified, a downstream component may choose a different encoding, either by assuming a default encoding or automatically inferring which encoding is being used, which can be erroneous. When the encodings are inconsistent, the downstream component might treat some character or byte sequences as special, even if they are not special in the original encoding. Attackers might then be able to exploit this discrepancy and conduct injection attacks; they even might be able to bypass protection mechanisms that assume the original encoding is also being used by the downstream component.

### Implementation (Input Validation)

Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked.

## Detection methods

### 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.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following web application code attempts to read an integer value from a request object. If the parseInt call fails, then the input is logged with an error message indicating what happened.

Bad code:

```java
String val = request.getParameter("val");
try {

    int value = Integer.parseInt(val);
}
catch (NumberFormatException) {
    log.info("Failed to parse val = " + val);
}
...
```

### Example 2

The following code records an error if a username's attempt at registration fails.

Bad code:

```php
$username = $_GET['username'];
try {
    if (strlen($username) > 20) {
        throw new Exception("Username too long");
    }
} catch (Exception $e) {
    error_log("User registration failed: " . $username);
}
```

Result code:

```
User registration failed: hacker
Admin Access Granted
```

Good code:

```php
function sanitize_for_log(string $input): string {
    // Remove all control characters including newlines, carriage returns, tabs, etc.
    $sanitized = preg_replace('/[[:cntrl:]]/', '', $input);
    // Trim leading/trailing whitespace
    return trim($sanitized);
}

function validate_username(string $input): string {
    // Sanitize first to strip any injected control characters
    $clean = sanitize_for_log($input);

    // Enforce max length
    if (strlen($clean) > 20) {
        throw new Exception("Username too long");
    }

    // Allowlist: only alphanumeric characters and underscores
    if (!preg_match('/^[a-zA-Z0-9_]+$/', $clean)) {
        throw new InvalidArgumentException("Username contains invalid characters");
    }

    return $clean;
}

$raw_username = $_GET['username'] ?? '';

try {
    $username = validate_username($raw_username);
    }
catch (LengthException $e) {
    $safe_log = sanitize_for_log($raw_username);
    error_log("User registration failed (too long): " . substr($safe_log, 0, 50));
}
catch (InvalidArgumentException $e) {
    $safe_log = sanitize_for_log($raw_username);
    error_log("User registration failed (invalid chars): " . substr($safe_log, 0, 50));
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2020-36567 | Go-based HTTP framework allows log injection via an encoded carriage return (%0a) |
| CVE-2006-4624 | Chain: inject fake log entries with fake timestamps using CRLF injection |

## Real CVEs with this weakness (sample of 12 of 145)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-118994 | CallBackery versions before 0.62.0 for Perl allow log injection via newlines in the login name | critical | 9.8 | - | No | 2026-10-30 |
| CVE-2026-17481 | IBM Documentation Offline is vulnerable to information disclosure, session forgery and remote code execution | critical | 9.8 | - | No | 2026-08-13 |
| CVE-2024-0987 | Sichuan Yougou Technology KuERP log neutralization for logs | critical | 9.8 | - | No | 2024-01-29 |
| CVE-2023-46321 | - | critical | 9.8 | - | No | 2023-10-22 |
| CVE-2023-46322 | - | critical | 9.8 | - | No | 2023-10-22 |
| CVE-2015-10011 | OpenDNS OpenResolve endpoints.py neutralization for logs | critical | 9.8 | - | No | 2023-01-02 |
| CVE-2026-81696 | openssl\_encrypt before 1.4.9 Terminal Injection via info Command | critical | 9.3 | - | No | 2026-08-27 |
| CVE-2026-81695 | openssl\_encrypt before 1.4.9 Terminal Injection via key\_id | critical | 9.3 | - | No | 2026-08-27 |
| CVE-2026-81694 | openssl-encrypt before 1.4.9 Output Injection via Unsanitized Filenames in verify-usb Command | critical | 9.3 | - | No | 2026-08-27 |
| CVE-2026-74885 | openssl\_encrypt before 1.4.0 Logging Bug and Race Condition | critical | 9.3 | - | No | 2026-08-17 |
| CVE-2024-47083 | Power Platform Terraform Provider has Improper Masking of Secrets in Logs | high | 8.8 | - | No | 2024-09-25 |
| CVE-2024-25047 | IBM Cognos Analytics log injection | high | 8.6 | - | No | 2024-05-02 |

## Related attack patterns (CAPEC)

- [CAPEC-268](https://radicalnotion.ai/capec/capec-268): Audit Log Manipulation
- [CAPEC-81](https://radicalnotion.ai/capec/capec-81): Web Server Logs Tampering
- [CAPEC-93](https://radicalnotion.ai/capec/capec-93): Log Injection-Tampering-Forging

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-20](https://radicalnotion.ai/cwe/cwe-20) | Improper Input Validation |
| Parent | [CWE-116](https://radicalnotion.ai/cwe/cwe-116) | Improper Encoding or Escaping of Output |
| Related | [CWE-93](https://radicalnotion.ai/cwe/cwe-93) | Improper Neutralization of CRLF Sequences |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Log Forging | - | - |
| Software Fault Patterns | Exposed Data | SFP23 | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not log unsanitized user input | IDS03-J | Exact |
| SEI CERT Oracle Coding Standard for Java | Do not log unsanitized user input | IDS03-J | Exact |
| OpenSSF Secure Coding Guide for Python | Neutralize Untrusted Data in Logs | pyscg-0022 | - |

## Frequently asked questions

### What is CWE-117?

The product constructs a log message from external input, but it does not neutralize or incorrectly neutralizes special elements when the message is written to a log file.

### What CVEs are caused by CWE-117?

145 recorded CVEs are attributed to CWE-117, including CVE-2026-118994, CVE-2026-17481 and CVE-2024-0987.

### How do you prevent CWE-117?

Assume 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.

### How is CWE-117 detected?

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.)

### What are the consequences of CWE-117?

Exploiting CWE-117 can lead to: Modify Application Data, Hide Activities, Execute Unauthorized Code or Commands.

### Is CWE-117 actively exploited?

145 recorded CVEs are caused by CWE-117; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/117.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-117). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
