CWEweakness

CWE-838 Inappropriate Encoding for Output Context

Official page ↗
Abstraction
Base
Structure
Simple
Status
Incomplete
Languages
Not Language-Specific
CWE version
5.0

Description

The product uses or specifies an encoding when generating output to a downstream component, but the specified encoding is not the same as the encoding that is expected by the downstream component.

Extended description

Using the correct output encoding is essential for ensuring that communications between components are accurate. For example, HTML entity encoding is used for elements in the HTML body of a web page. However, a programmer might use entity encoding when generating output that is used within an attribute of an HTML tag, which could contain functional Javascript that is not affected by the HTML encoding. While web applications have received the most attention for this problem, this weakness could potentially apply to any type of product that uses a communications stream that could support multiple encodings.

Common consequences

• Integrity, Confidentiality, Availability: Modify Application Data, Execute Unauthorized Code or Commands — An attacker could modify the structure of the message or data being sent to the downstream component. When the wrong encoding is used - even if closely related - the downstream component could decode the data incorrectly and misinterpret the output. This can have security consequences when the provided boundaries between control and data are inadvertently broken, because the resulting data could introduce control characters or special elements that were not sent by the product. The resulting data could then be used to bypass protection mechanisms such as input validation, and enable injection attacks.

Potential mitigations

• [Implementation] Use context-aware encoding. That is, understand which encoding is being used by the downstream component, and ensure that this encoding is used. If an encoding can be specified, do so, instead of assuming that the default encoding is the same as the default being assumed by the downstream component. • [Architecture and Design] Where possible, use communications protocols or data formats that provide strict boundaries between control and data. If this is not feasible, ensure that the protocols or formats allow the communicating components to explicitly state which encoding/decoding method is being used. Some template frameworks provide built-in support. • [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. Note that some template mechanisms provide built-in support for the appropriate encoding.

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

Observed examples

• CVE-2009-2814: Server does not properly handle requests that do not contain UTF-8 data; browser assumes UTF-8, allowing XSS.

Related

Attack pattern · CAPEC (1)

  • CAPEC-468 Generic Cross-Browser Cross-Domain Theft attack pattern

Observed example · CVE (1)

  • CVE-2009-2814 Cross-site scripting (XSS) vulnerability in the Wiki Server in Apple Mac OS X 10.5.8 allows remote attackers to inject arbitrary web script… vulnerability

Child of · CWE (1)

  • CWE-116 Improper Encoding or Escaping of Output weakness

Referenced by CAPEC · weakness (1)

  • CAPEC-468 Generic Cross-Browser Cross-Domain Theft attack pattern

Referenced by CVE · weakness (18)

  • CVE-2026-114650 A flaw in the client-side encryption support of the MongoDB .NET/C# driver can cause data designated for client-side field-level encryption… vulnerability
  • CVE-2026-84463 Zammad is a web based open source helpdesk/customer support system. vulnerability
  • CVE-2026-55858 MariaDB Connector/J is used to connect applications developed in Java to MariaDB and MySQL databases. vulnerability
  • CVE-2026-55859 MariaDB Connector/R2DBC is a non-blocking MariaDB and MySQL client implemented in Java. vulnerability
  • CVE-2026-47079 Inappropriate Encoding for Output Context vulnerability in joshnuss xml_builder (XmlBuilder module) allows Content Spoofing, Cross-site… vulnerability
  • CVE-2026-53641 FOSSBilling is a free, open-source billing and client management system. vulnerability
  • CVE-2025-4052 Inappropriate implementation in DevTools in Google Chrome prior to 136.0.7103.59 allowed a remote attacker who convinced a user to engage… vulnerability
  • CVE-2024-11702 Copying sensitive information from Private Browsing tabs on Android, such as passwords, may have inadvertently stored data in the… vulnerability
  • CVE-2024-34006 The site log report required additional encoding of event descriptions to ensure any HTML in the content is displayed in plaintext instead… vulnerability
  • CVE-2023-5770 Proofpoint Enterprise Protection contains a vulnerability in the email delivery agent that allows an unauthenticated attacker to inject… vulnerability
  • CVE-2023-6512 Inappropriate implementation in Web Browser UI in Google Chrome prior to 120.0.6099.62 allowed a remote attacker to potentially spoof the… vulnerability
  • CVE-2023-3735 Inappropriate implementation in Web API Permission Prompts in Google Chrome prior to 115.0.5790.98 allowed a remote attacker to obfuscate… vulnerability
  • CVE-2020-29135 cPanel before 90.0.17 has multiple instances of URL parameter injection (SEC-567). vulnerability
  • CVE-2020-7292 Inappropriate Encoding for output context vulnerability in McAfee Web Gateway (MWG) prior to 9.2.1 allows a remote attacker to cause MWG to… vulnerability
  • CVE-2020-10996 An issue was discovered in Percona XtraDB Cluster before 5.7.28-31.41.2. vulnerability
  • CVE-2019-18981 Pimcore before 6.2.2 lacks an Access Denied outcome for a certain scenario of an incorrect recipient ID of a notification. vulnerability
  • CVE-2019-6110 In OpenSSH 7.9, due to accepting and displaying arbitrary stderr output from the server, a malicious server (or Man-in-The-Middle attacker)… vulnerability
  • CVE-2018-9862 util.c in runV 1.0.0 for Docker mishandles a numeric username, which allows attackers to obtain root access by leveraging the presence of… vulnerability

Referenced by CWE · has member (1)