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
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
This rule shares the following common options: excludes, includes, justification_checker, post_processing, provider, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.