CWE-838: Inappropriate Encoding for Output Context
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
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.
常见后果
影响范围: 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, possibly injecting commands.
潜在缓解措施
阶段: Implementation
策略: Output Encoding
描述: 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
策略: Output Encoding
描述: 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
策略: Libraries or Frameworks
检测方法
方法: 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.)
有效性: High
观察示例
参考: CVE-2009-2814
Server does not properly handle requests that do not contain UTF-8 data; browser assumes UTF-8, allowing XSS.
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| The CERT Oracle Secure Coding Standard for Java (2011) | IDS13-J | Use compatible encodings on both sides of file or network IO | - |