Base · Medium

CWE-182: Collapse of Data into Unsafe Value

The product filters data in a way that causes it to be reduced or "collapsed" into an unsafe value that violates an expected security property.

CWE-182 · Base Level ·6 CVEs ·4 Mitigations

Description

The product filters data in a way that causes it to be reduced or "collapsed" into an unsafe value that violates an expected security property.

Potential Impact

Access Control

Bypass Protection Mechanism

Mitigations & Prevention

Architecture and Design

Avoid making decisions based on names of resources (e.g. files) if those resources can have alternate names.

Implementation

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 relat

Implementation

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.

General

Canonicalize the name to match that of the file system's representation of the name. This can sometimes be achieved with an available API (e.g. in Win32 the GetFullPathName function).

Detection Methods

  • Automated Static Analysis High — 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 sea

Real-World CVE Examples

CVE IDDescription
CVE-2004-0815"/.////" in pathname collapses to absolute path.
CVE-2005-3123"/.//..//////././" is collapsed into "/.././" after ".." and "//" sequences are removed.
CVE-2002-0325".../...//" collapsed to "..." due to removal of "./" in web server.
CVE-2002-0784chain: HTTP server protects against ".." but allows "." variants such as "////./../.../". If the server removes "/.." sequences, the result would collapse into an unsafe value "////../" (CWE-182).
CVE-2005-2169MFV. Regular expression intended to protect against directory traversal reduces ".../...//" to "../".
CVE-2001-1157XSS protection mechanism strips a <script> sequence that is nested in another <script> sequence.

Taxonomy Mappings

  • PLOVER: — Collapse of Data into Unsafe Value
  • The CERT Oracle Secure Coding Standard for Java (2011): IDS11-J — Eliminate noncharacter code points before validation

Frequently Asked Questions

What is CWE-182?

CWE-182 (Collapse of Data into Unsafe Value) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product filters data in a way that causes it to be reduced or "collapsed" into an unsafe value that violates an expected security property.

How can CWE-182 be exploited?

Attackers can exploit CWE-182 (Collapse of Data into Unsafe Value) to bypass protection mechanism. This weakness is typically introduced during the Implementation phase of software development.

How do I prevent CWE-182?

Key mitigations include: Avoid making decisions based on names of resources (e.g. files) if those resources can have alternate names.

What is the severity of CWE-182?

CWE-182 is classified as a Base-level weakness (Medium abstraction). It has been observed in 6 real-world CVEs.