CWE-434: Unrestricted Upload of File with Dangerous Type

Base Draft Simple

CWE版本: 4.18

更新日期: 2025-09-09

弱点描述

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

常见后果

影响范围: Integrity Confidentiality Availability

技术影响: Execute Unauthorized Code or Commands

说明: Arbitrary code execution is possible if an uploaded file is interpreted and executed as code by the recipient. This is especially true for web-server extensions such as .asp and .php because these file types are often treated as automatically executable, even when file system permissions do not specify execution. For example, in Unix environments, programs typically cannot run unless the execute bit is set, but PHP programs may be executed by the web server without directly invoking them on the operating system.

潜在缓解措施

阶段: 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

策略: Enforcement by Conversion

描述: 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

策略: Input Validation

阶段: 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

策略: Input Validation

描述: 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.

阶段: Implementation

描述: Do not rely exclusively on sanity checks of file contents to ensure that the file is of the expected type and size. It may be possible for an attacker to hide code in some file segments that will still be executed by the server. For example, GIF images may contain a free-form comments field.

阶段: Implementation

描述: Do not rely exclusively on the MIME content type or filename attribute when determining how to render a file. Validating the MIME content type and ensuring that it matches the extension is only a partial solution.

阶段: Architecture and Design Operation

策略: Environment Hardening

描述: Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.

阶段: Architecture and Design Operation

策略: Sandbox or Jail

有效性: Limited

检测方法

方法: Dynamic Analysis with Automated Results Interpretation

有效性: SOAR Partial

方法: Dynamic Analysis with Manual Results Interpretation

有效性: SOAR Partial

方法: Manual Static Analysis - Source Code

有效性: High

方法: Automated Static Analysis - Source Code

有效性: High

方法: Architecture or Design Review

有效性: High

观察示例

参考: 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

引入模式

阶段 说明
Implementation -
Architecture and Design OMISSION: This weakness is caused by missing a security tactic during the architecture and design phase.

适用平台

编程语言
ASP.NET (Sometimes) PHP (Often) Not Language-Specific (Undetermined)
技术
Web Server (Sometimes)

分类映射

分类名称 条目ID 条目名称 映射适配度
PLOVER - Unrestricted File Upload -
OWASP Top Ten 2007 A3 Malicious File Execution CWE More Specific
OMG ASCSM ASCSM-CWE-434 -
关键信息

CWE ID: CWE-434

抽象级别: Base

结构: Simple

状态: Draft

利用可能性: Medium

相关弱点
相关攻击模式
CAPEC-1