
Cloud Vulnerability DB
A community-led vulnerabilities database
FileUpload::create() validates the allowedTypes option against $fileData['type'], which is the Content-Type sent by the client. The uploaded content itself is never inspected, so a file of any content (e.g. PHP source, HTML, SVG) passes an "images only" policy by being labelled image/jpeg. isImage() is based on the same client value. Applications that rely on allowedTypes without allowedExtensions, store files under the client-supplied filename, and store them in a directory where PHP is executed are exposed to remote code execution. Otherwise the impact is limited to unexpected content being accepted (e.g. stored XSS if uploads are served back).
Location: src/FileUpload.php, FileUpload::create(), allowedTypes check. In $_FILES, the 'type' value comes from the multipart Content-Type header and is fully controlled by the client. create() compares only this value with allowedTypes. The temporary file (tmp_name) is not examined, although the package already requires ext-fileinfo and uses mime_content_type() in fromFile(). The reference implementation tests/Example/UploadHandler.php uses allowedTypes without allowedExtensions and stores the file under basename($upload->name), which meets two of the three preconditions for code execution. Fix: when allowedTypes is set, create() now also detects the MIME type from the uploaded content with mime_content_type() and requires it to be in the list. If the type cannot be detected, the upload is rejected. The existing check of the client-supplied type is kept. The fix was contributed by @iefken. Note: allowlist entries that libmagic never reports (e.g. image/jpg, or text/csv, which may be detected as text/plain) will now reject those files until the detected type is added. Content detection does not replace extension validation; use allowedExtensions or generate the stored filename on the server.
<?php
require 'vendor/autoload.php';
use Koriym\FileUpload\FileUpload;
$tmp = tempnam(sys_get_temp_dir(), 'poc');
file_put_contents($tmp, "<?php\n// not an image\n");
$upload = FileUpload::create([
'name' => 'avatar.php',
'type' => 'image/jpeg', // client-supplied
'size' => filesize($tmp),
'tmp_name' => $tmp,
'error' => UPLOAD_ERR_OK,
], ['allowedTypes' => ['image/jpeg', 'image/png', 'image/gif']]);
var_dump(mime_content_type($tmp)); // "text/x-php"
var_dump($upload::class); // FileUpload (accepted) in <= 1.0.0
var_dump($upload->isImage()); // trueThis is a validation bypass (CWE-434 / CWE-345). Applications using koriym/file-upload <= 1.0.0 that rely on the allowedTypes option to restrict which files are accepted are affected: any content is accepted as long as the client labels it with an allowed MIME type. Remote code execution is possible only when an application also (1) does not use allowedExtensions, (2) stores the file under the client-supplied filename, and (3) stores it in a directory where the web server executes PHP. The example UploadHandler in this repository meets (1) and (2). Applications that serve uploaded files back may be exposed to stored XSS (HTML/SVG accepted as images). Users should upgrade to 1.0.1. As a workaround, always use allowedExtensions together with allowedTypes, or generate the stored filename on the server, and store uploads outside directories where PHP is executed.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."