CWE-434

AI-generated file upload handlers often lack file type validation, size limits, and proper storage configuration, enabling arbitrary file upload attacks....

Verified by Precogs Threat Research
BASE SCORE
7.5 CRITICAL

Precogs AI Insight

"Precogs AI identifies unrestricted file uploads in AI-generated code and generates validation middleware with type checking and size limits."

EXPLOIT PROBABILITYHigh
PUBLIC POCAvailable

What is CWE-434 (Unrestricted Upload of File with Dangerous Type)?

AI-generated file upload handlers often lack file type validation, size limits, and proper storage configuration, enabling arbitrary file upload attacks.

Vulnerability Insights

In the context of vulnerabilities in ai-generated code, this vulnerability poses significant risk because compiled binaries and complex AI logic cannot be easily patched without vendor cooperation. Organizations relying on third-party software must use structural analysis tools to detect these flaws.

Impact on Systems

  • Remote Code Execution (RCE): Uploading and executing a web shell
  • Malware Distribution: Hosting malicious payloads for other users to download
  • Defacement: Overwriting critical application files

Real-World Attack Scenario

An attacker targets an avatar upload feature. Instead of an image, they upload a .php script containing a web shell. The server places the file in a publicly accessible uploads/ directory without altering its extension. The attacker then navigates to domain.com/uploads/webshell.php, forcing the server to execute their malicious script, leading to full server compromise.

Code Examples

Vulnerable Implementation

// VULNERABLE: Moves the uploaded file based purely on the supplied filename
$target_path = "uploads/" . basename($_FILES['uploadedfile']['name']);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);

Secure Alternative

// SECURE: Validates extension, renames file, stores outside web root
$ext = pathinfo($_FILES['uploadedfile']['name'], PATHINFO_EXTENSION);
if (in_array($ext, ['jpg', 'png'])) {
    $new_name = uniqid() . "." . $ext;
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "/safe/outside/webdir/" . $new_name);
}

Remediation

Ensure robust input validation, boundary checking, and adherence to secure architecture frameworks when designing AI-Generated Code solutions. Use automated code scanning or binary analysis to detect flaws early in the SDLC.