Umbra Wiki weakness weakness/CWE-434
Back to wiki

CWE-434 — Unrestricted Upload of File with Dangerous Type

provenance: imported · CWE: CWE-434

CWE-434: Unrestricted Upload of File with Dangerous Type

MITRE CWE weakness

Kind Weakness
Abstraction Base
Status Draft
Likelihood of exploit Medium

Description

The product allows the upload or transfer of dangerous file types that are automatically processed within its environment.

Common consequences

  • Integrity, Confidentiality, Availability: Execute Unauthorized Code or Commands

Mitigations

Architecture and Design — Generate a new, unique filename for an uploaded file instead of using the user-supplied filename, so that no external input is used at all.[REF-422] [REF-423]

Architecture and Design — When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.

Architecture and Design — Consider storing the uploaded files outside of the web document root entirely. Then, use other mechanisms to deliver the files dynamically. [REF-423]

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 related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. For example, limiting filenames to alphanumeric characters can help to restrict the introduction of unintended file extensions.

Architecture and Design — Define a very limited set of allowable extensions and only generate filenames that end in these extensions. Consider the possibility of XSS (CWE-79) before allowing .html or .htm file types.

References

  • CWE page: https://cwe.mitre.org/data/definitions/434.html
  • CWE list: https://cwe.mitre.org/data/index.html