Insecure File Upload
Overview
Unrestricted file upload allows attackers to upload web shells (PHP, JSP, ASPX) or other malicious files that can then be executed by the server. This often leads to Remote Code Execution.
Attack scenarios:
- Upload
shell.php— server executes it if stored in webroot - Upload a file with double extension:
shell.php.jpg— some servers still execute - Upload SVG with embedded XSS — client-side attack
- Upload oversized file — DoS via disk exhaustion
Detection Strategy
move_uploaded_file()without extension whitelist checkmulterstorage without file type validation- Upload directory inside webroot
- Trust of
Content-Typeheader alone (user-controlled)
Remediation
- Whitelist allowed extensions (not blacklist)
- Validate MIME type using file content (magic bytes), not only headers
- Store uploaded files outside webroot
- Rename uploaded files to random UUIDs
- Scan with antivirus for high-risk applications
- Set file size limits