CWE WEAKNESSES / CWE-434
CWE-434
Unrestricted Upload of File with Dangerous Type
Base EXPLOIT LIKELIHOOD: MEDIUM
What it is
The product allows the upload or transfer of dangerous file types that are automatically processed within its environment.
Impact
| 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 r
- [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.
- [Implementation] Ensure that only one extension is used in the filename. Some web servers, including some versions of Apache, may process files based on inner extensions so that "filename.php.gif" is fed to the PHP interpreter.[REF-422] [REF-423]
- [Implementation] When running on a web server that supports case-insensitive filenames, perform case-insensitive evaluations of the extensions that are provided.
- [Architecture and Design] For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
Real-world CVE examples
- CVE-2023-5227 — PHP-based FAQ management app does not check the MIME type for uploaded images
- CVE-2001-0901 — Web-based mail product stores ".shtml" attachments that could contain SSI
- CVE-2002-1841 — PHP upload does not restrict file types
- CVE-2005-1868 — upload and execution of .php file
- CVE-2005-1881 — upload file with dangerous extension
- CVE-2005-0254 — program does not restrict file types
- CVE-2004-2262 — improper type checking of uploaded files
- CVE-2006-4558 — Double "php" extension leaves an active php extension in the generated filename.
- CVE-2006-6994 — ASP program allows upload of .asp files by bypassing client-side checks
- CVE-2005-3288 — ASP file upload
- CVE-2006-2428 — ASP file upload
Related weaknesses
Test & detect
Browse all common weaknesses, check related exploited CVEs, or map to ATT&CK techniques.
Source: MITRE CWE. View on cwe.mitre.org →