---
title: "CWE-116: Improper Encoding or Escaping of Output"
url: https://radicalnotion.ai/cwe/cwe-116
type: cwe
description: "The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-116: Improper Encoding or Escaping of Output

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 386
- **Of those, in CISA KEV:** 5
- **New in 2026:** 157
- **CWE catalog version:** 4.21

## Description

The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.

## Background

Most products follow a certain protocol that uses structured messages for communication between components, such as queries or commands. These structured messages can contain raw data interspersed with metadata or control information. For example, "GET /index.html HTTP/1.1" is a structured message containing a command ("GET") with a single argument ("/index.html") and metadata about which protocol version is being used ("HTTP/1.1").

## Alternate terms

- Output Sanitization
- Output Validation
- Output Encoding

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |
| Operation | - |

## Applicable platforms

**Languages:** Go (Undetermined)

**Technologies:** AI/ML (Undetermined), Database Server (Often), Web Server (Often)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality, Availability, Access Control | Modify Application Data, Execute Unauthorized Code or Commands, Bypass Protection Mechanism | The communications between components can be modified in unexpected ways. If an application uses attacker-supplied inputs to construct a structured message without properly encoding or escaping, then the attacker could insert special characters that will cause the data to be misinterpreted as control information or metadata. As a result, the component that receives the output will perform the wrong operations, or otherwise interpret the data incorrectly. Attackers could change the commands that are sent to another component, inserting malicious commands instead, bypassing other security mechanisms. |

## Potential mitigations

### Architecture and Design (Libraries or Frameworks)

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.

Alternately, use built-in functions, but consider using wrappers in case those functions are discovered to have a vulnerability.

### Architecture and Design (Parameterization)

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.

For example, stored procedures can enforce database query structure and reduce the likelihood of SQL injection.

### Architecture and Design, Implementation

Understand the context in which your data will be used and the encoding that will be expected. This is especially important when transmitting data between different components, or when generating outputs that can contain multiple encodings at the same time, such as web pages or multi-part mail messages. Study all expected communication protocols and data representations to determine the required encoding strategies.

### Architecture and Design

In some cases, input validation may be an important strategy when output encoding is not a complete solution. For example, you may be providing the same output that will be processed by multiple consumers that use different encodings or representations. In other cases, you may be required to allow user-supplied input to contain control information, such as limited HTML tags that support formatting in a wiki or bulletin board. When this type of requirement must be met, use an extremely strict allowlist to limit which control sequences can be used. Verify that the resulting syntactic structure is what you expect. Use your normal encoding methods for the remainder of the input.

### Architecture and Design

Use input validation as a defense-in-depth measure to reduce the likelihood of output encoding errors (see CWE-20).

### Requirements

Fully specify which encodings are required by components that will be communicating with each other.

### Implementation

When exchanging data between components, ensure that both components are using the same character encoding. Ensure that the proper encoding is applied at each interface. Explicitly set the encoding you are using whenever the protocol allows you to do so.

## Detection methods

### Automated Static Analysis

This weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives.

Effectiveness: Moderate. This is not a perfect solution, since 100% accuracy and coverage are not feasible.

### Automated Dynamic Analysis

This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.

## Demonstrative examples

### Example 1

This code displays an email address that was submitted as part of a form.

Bad code:

```jsp
<% String email = request.getParameter("email"); %>
...
Email Address: <%= email %>
```

The value read from the form parameter is reflected back to the client browser without having been encoded prior to output, allowing various XSS attacks (CWE-79).

### Example 2

Consider a chat application in which a front-end web application communicates with a back-end server. The back-end is legacy code that does not perform authentication or authorization, so the front-end must implement it. The chat protocol supports two commands, SAY and BAN, although only administrators can use the BAN command. Each argument must be separated by a single space. The raw inputs are URL-encoded. The messaging protocol allows multiple commands to be specified on the same line if they are separated by a "\|" character.

Bad code:

```perl
$inputString = readLineFromFileHandle($serverFH);

# generate an array of strings separated by the "|" character.
@commands = split(/\|/, $inputString);

foreach $cmd (@commands) {

    # separate the operator from its arguments based on a single whitespace
    ($operator, $args) = split(/ /, $cmd, 2);

    $args = UrlDecode($args);
    if ($operator eq "BAN") {
        ExecuteBan($args);
    }
    elsif ($operator eq "SAY") {
        ExecuteSay($args);
    }
}
```

Bad code:

```perl
$inputString = GetUntrustedArgument("command");
($cmd, $argstr) = split(/\s+/, $inputString, 2);

# removes extra whitespace and also changes CRLF's to spaces
$argstr =~ s/\s+/ /gs;

$argstr = UrlEncode($argstr);
if (($cmd eq "BAN") && (! IsAdministrator($username))) {
    die "Error: you are not the admin.\n";
}

# communicate with file server using a file handle
$fh = GetServerFileHandle("myserver");

print $fh "$cmd $argstr\n";
```

Attack code:

```
SAY hello world|BAN user12
```

Result code:

```
SAY hello%20world|BAN%20user12
```

Result code:

```
SAY hello world
BAN user12
```

### Example 3

This example takes user input, passes it through an encoding scheme, then lists the contents of the user's home directory based on the user name.

Bad code:

```perl
sub GetUntrustedInput {
    return($ARGV[0]);
}

sub encode {
    my($str) = @_;
    $str =~ s/\&/\&amp;/gs;
    $str =~ s/\"/\&quot;/gs;
    $str =~ s/\'/\&apos;/gs;
    $str =~ s/\</\&lt;/gs;
    $str =~ s/\>/\&gt;/gs;
    return($str);
}

sub doit {
    my $uname = encode(GetUntrustedInput("username"));
    print "<b>Welcome, $uname!</b><p>\n";
    system("cd /home/$uname; /bin/ls -l");
}
```

Attack code:

```
' pwd
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2021-41232 | Chain: authentication routine in Go-based agile development product does not escape user name (CWE-116), allowing LDAP injection (CWE-90) |
| CVE-2008-4636 | OS command injection in backup software using shell metacharacters in a filename; correct behavior would require that this filename could not be changed. |
| CVE-2008-0769 | Web application does not set the charset when sending a page to a browser, allowing for XSS exploitation when a browser chooses an unexpected encoding. |
| CVE-2008-0005 | Program does not set the charset when sending a page to a browser, allowing for XSS exploitation when a browser chooses an unexpected encoding. |
| CVE-2008-5573 | SQL injection via password parameter; a strong password might contain "&" |
| CVE-2008-3773 | Cross-site scripting in chat application via a message subject, which normally might contain "&" and other XSS-related characters. |
| CVE-2008-0757 | Cross-site scripting in chat application via a message, which normally might be allowed to contain arbitrary content. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2024-10441 | Synology DiskStation Manager (DSM) Improper Encoding or Escaping of Output Vulnerability | critical | 9.8 | - | Yes | 2025-03-19 |
| CVE-2024-38475 | Apache HTTP Server weakness in mod\_rewrite when first segment of substitution matches filesystem path. | critical | 9.3 | - | Yes | 2024-07-01 |
| CVE-2022-42948 | Fortra Cobalt Strike User Interface Remote Code Execution Vulnerability | high | 8.7 | - | Yes | 2023-03-24 |
| CVE-2026-20245 | Cisco Catalyst SD-WAN Controller Authenticated Privilege Escalation Vulnerability | high | 7.8 | - | Yes | 2026-06-04 |
| CVE-2022-24682 | Synacor Zimbra Collaborate Suite (ZCS) Cross-Site Scripting Vulnerability | medium | 6.4 | - | Yes | 2022-02-09 |
| CVE-2025-55730 | XWiki Remote Macros vulnerable to remote code execution using the confluence paste code macro | critical | 10.0 | - | No | 2025-09-09 |
| CVE-2025-55729 | XWiki Remote Macros vulnerable to remote code execution using the ConfluenceLayoutSection macro | critical | 10.0 | - | No | 2025-09-09 |
| CVE-2023-26472 | XWiki Platform vulnerable to privilege escalation via async macro and IconThemeSheet from the user profile | critical | 10.0 | - | No | 2023-03-02 |
| CVE-2022-23603 | Code injection in iTunesRPC-Remastered | critical | 9.9 | - | No | 2022-02-01 |
| CVE-2026-126170 | - | critical | 9.8 | - | No | 2026-11-11 |
| CVE-2026-120647 | CGI versions before 5.00 for Perl allow Content-Disposition parameter injection via unescaped double quotes in the header attachment filename | critical | 9.8 | - | No | 2026-11-03 |
| CVE-2026-110757 | Text::CSV\_XS versions before 1.65 for Perl allow record splitting by writing strings used as numbers without quotes in combine | critical | 9.8 | - | No | 2026-10-16 |

## Related attack patterns (CAPEC)

- [CAPEC-104](https://radicalnotion.ai/capec/capec-104): Cross Zone Scripting
- [CAPEC-73](https://radicalnotion.ai/capec/capec-73): User-Controlled Filename
- [CAPEC-81](https://radicalnotion.ai/capec/capec-81): Web Server Logs Tampering
- [CAPEC-85](https://radicalnotion.ai/capec/capec-85): AJAX Footprinting

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-707](https://radicalnotion.ai/cwe/cwe-707) | Improper Neutralization |
| Child | [CWE-117](https://radicalnotion.ai/cwe/cwe-117) | Improper Output Neutralization for Logs |
| Child | [CWE-644](https://radicalnotion.ai/cwe/cwe-644) | Improper Neutralization of HTTP Headers for Scripting Syntax |
| Child | [CWE-838](https://radicalnotion.ai/cwe/cwe-838) | Inappropriate Encoding for Output Context |
| Can precede | [CWE-74](https://radicalnotion.ai/cwe/cwe-74) | Improper Neutralization of Special Elements in Output Used by a Downstream Component |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| WASC | Improper Output Handling | 22 | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Sanitize untrusted data passed across a trust boundary | IDS00-J | Exact |
| The CERT Oracle Secure Coding Standard for Java (2011) | Use a subset of ASCII for file and path names | IDS05-J | - |
| SEI CERT Oracle Coding Standard for Java | Prevent SQL injection | IDS00-J | Imprecise |
| SEI CERT Perl Coding Standard | Sanitize untrusted data passed across a trust boundary | IDS33-PL | Exact |
| OWASP Golang Secure Coding Practices Guide | Output Encoding | - | - |

## Frequently asked questions

### What is CWE-116?

The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.

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

386 recorded CVEs are attributed to CWE-116, including CVE-2024-10441, CVE-2024-38475 and CVE-2022-42948. 5 are listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### Is CWE-116 part of the OWASP Top 10?

CWE-116 maps to OWASP Golang Secure Coding Practices Guide: Output Encoding in the OWASP security taxonomy.

### How do you prevent CWE-116?

Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.

### How is CWE-116 detected?

Automated Static Analysis: This weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives.

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

Exploiting CWE-116 can lead to: Modify Application Data, Execute Unauthorized Code or Commands, Bypass Protection Mechanism.

### Is CWE-116 actively exploited?

Yes. 5 CWE-116 vulnerabilities are in CISA's KEV catalog of actively exploited flaws, out of 386 recorded CVEs.

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

---

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