Use wp_handle_upload() with MIME Allowlists for File Uploads
Share
Direct move_uploaded_file() with only client-supplied MIME checks enables shell upload. Use wp_handle_upload() which validates both extension and file content. [CWE-434 · A04:2021]
Why This Matters
prevents remote code execution and malicious file serving through unrestricted uploads
Use wp_handle_upload() with MIME Allowlists for File Uploads
Impact: HIGH (prevents remote code execution and malicious file serving through unrestricted uploads)
WordPress provides wp_handle_upload() which validates file extensions against the allowed MIME types, checks file content via finfo, generates unique filenames, and places files in the correct uploads directory. Using move_uploaded_file() directly bypasses all of these protections.
CVE-2024-43243 (JobBoard plugin) — mime_content_type() was the only check, allowing .php files disguised as images. CVE-2024-13342 (Booster for WooCommerce) — double-extension files bypassed the MIME whitelist.