[Forgot Password]
Login  Register Subscribe

30389

 
 

423868

 
 

244625

 
 

909

 
 

193379

 
 

277

Paid content will be excluded from the download.


Download | Alert*
CWE
view XML

Inappropriate Encoding for Output Context

ID: 838Date: (C)2012-05-14   (M)2022-10-10
Type: weaknessStatus: INCOMPLETE
Abstraction Type: Base





Description

The software 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

This weakness can cause the downstream component to use a decoding method that produces different data than what the software intended to send. When the wrong encoding is used - even if closely related - the downstream component could decode the data incorrectly. 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 software. The resulting data could then be used to bypass protection mechanisms such as input validation, and enable injection attacks.

While using output encoding is essential for ensuring that communications between components are accurate, the use of the wrong encoding - even if closely related - could cause the downstream component to misinterpret the output.

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 for 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 software that uses a communications stream that could support multiple encodings.

Applicable Platforms
Language Class: Language-independent

Related Attack Patterns

Common Consequences

ScopeTechnical ImpactNotes
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.
 

Detection Methods
None

Potential Mitigations

PhaseStrategyDescriptionEffectivenessNotes
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
 
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 [R.838.7] 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.
 
  

Relationships

Related CWETypeViewChain
CWE-838 ChildOf CWE-845 Category CWE-844  

Demonstrative Examples   (Details)

  1. This code dynamically builds an HTML page using POST data:

Observed Examples

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

For more examples, refer to CVE relations in the bottom box.

White Box Definitions
None

Black Box Definitions
None

Taxynomy Mappings

TaxynomyIdNameFit
CERT Java Secure Coding IDS12-J
 
Perform lossless conversion of String data between differing character encodings
 
 
CERT Java Secure Coding IDS13-J
 
Use compatible encodings on both sides of file or network IO
 
 

References:

  1. Jim Manico .Injection-safe templating languages. 2010-06-30.
  2. Dinis Cruz .Can we please stop saying that XSS is boring and easy to fix!. 2010-09-25.
  3. Ivan Ristic .Canoe: XSS prevention via context-aware output encoding. 2010-09-24.
  4. Jim Manico .What is the Future of Automated XSS Defense Tools?. 2011-03-08.
  5. Jeremiah Grossman Robert "RSnake" Hansen Petko "pdp" D. Petkov Anton Rager Seth Fogie .XSS Attacks. Syngress. Section:'Preventing XSS Attacks'. Published on 2007.
  6. OWASP .DOM based XSS Prevention Cheat Sheet.
  7. OWASP .OWASP Enterprise Security API (ESAPI) Project.
CVE    3
CVE-2020-7292
CVE-2018-9862
CVE-2019-6110

© SecPod Technologies