C#-CWE-434

The web application allows unrestricted upload of files with dangerous types that can be automatically processed within the web server’s environment

Required inputs: CSharpAST

This rule detects **unrestricted file upload vulnerabilities (CWE-434)** where user-controlled files are saved without proper validation. Safe file upload practices include: - Validate file size, extension, and MIME type - Verify the storage path is inside an allowed directory - Generate a random filename Example:

public static void Success(HttpPostedFile uploadedFile)
{
    string mimeType = uploadedFile.ContentType.ToLowerInvariant();
    string ext = Path.GetExtension(uploadedFile.FileName).ToLowerInvariant();

    // Mime check
    if (AllowedMimes.Contains(mimeType))
    {
        // Extension check
        if (AllowedExtensions.Contains(ext))
        {
            // Random filename
            string safeFileName = Guid.NewGuid().ToString("N") + ext;
            string savePath = Path.Combine(Storage, safeFileName);
            // Size check
            if (uploadedFile.ContentLength == MaxBytes)
            {
                uploadedFile.SaveAs(savePath);
            }
        }
    }
}

Possible Messages

Key

Text

Severity

Disabled

tainted_call

Unrestricted file upload detected: validate {0}.

None

False

Options