Insecure file upload In codeigniter4/framework
Description
CodeIgniter4 has a validation bypass when uploading file extensions via ext_in rule
Impact
The ext_in upload validation rule checked the MIME-derived guessed extension instead of the client-provided filename extension. As a result, an uploaded file named shell.php containing GIF-like content could pass validation such as:
uploaded[avatar]|is_image[avatar]|mime_in[avatar,image/gif]|ext_in[avatar,gif]
because the detected MIME type maps to gif, even though the uploaded filename extension is php.
Applications are impacted if they:
accept user-controlled uploads,
rely on ext_in to validate the uploaded filename extension,
save uploaded files using the original client filename: $file->move($path),
store uploads in a web-accessible directory,
and allow PHP or other executable files to run from that directory.
In those conditions, this may lead to arbitrary code execution. The default application does not expose such an upload endpoint.
Patches
Upgrade to v4.7.3 or later.
Workarounds
Save uploads outside the public web root, preferably under writable/uploads
Use $file->store() or $file->move($path, $file->getRandomName()) instead of preserving the original filename
Disable script execution in any public upload directory
Manually verify the client filename extension before moving the file
Reject files when $file->getClientExtension() is not in the allowed list or does not match $file->guessExtension()
Resources
Mitigation
Update Impact
Minimal update. May introduce new vulnerabilities or breaking changes.
Ecosystem | Component | Affected version | Patched versions |
|---|---|---|---|
packagist | 4.7.3 |
Aliases
References