FILE UPLOADS
the methods described here are the exploitation of file upload forms and functionalities
PAYLOADS
MITIGATION
EXTENSION VALIDATION
use whitelisting to allow specific extension extensions and blacklisting to restrict dangerous extensions. this way, the blacklist list will prevent uploading malicious scripts if the whitelist is ever bypassed. this MUST be applied to both the back-end and front-end file validation.
CONTENT VALIDATION
in addition to extension validation, file content MUST also be validated and ensure that the file extension matches the file's content.
AVOID UPLOAD DISCLOSURE
restrict disclosing the uploads directory or providing direct access to the uploaded file. It is always recommended to hide the uploads directory from the end-users and only allow them to download the uploaded files through a download page. utilize a download.php script that fetches a requested file to be downloaded from the uploads directory. this can significantly reduce the chances of accessing a maliciously uploaded script to execute code. if a download page is utilized, ensure the download.php only grants access to files owned by the users to prevent IDOR/LFI vulnerabilities. this can be achieved by utilizing the Content-Disposition and nosniff headers and using an accurate Contrent-Type header. lastly, implement a filename randomization mechanism for the uploaded files and only store "sanitized" original names in a database. this prevents users from knowing the uploads directory nor the uploaded file name.
CONFIGURATION SECURITY
disable specific functions that may be used to execute system commands through the web application. for instance, use the disable_functions configuration in php.ini. lastly, always handle errors at the web application level and print out simple errors that explain the error without disclosing any sensitive or specific details, like the file name, uploads directory, or the raw errors.
Limit file size
Update any used libraries
Scan uploaded files for malware or malicious strings
Utilize a Web Application Firewall (WAF) as a secondary layer of protection
Last updated