Avatar image upload and bypass real image verification
The avatar upload form only checks the MIME type reported by the image library, so a file with a PHP extension but a valid JPEG header passes verification. An attacker could upload a PHP file disguised as an image, though the report notes the file is renamed on the server, limiting immediate risk.
- Disclosed after 7 months
Hi
We can bypass Avatar Upload image verification and extension uploading a php file or any other extension binding a valide jpeg image , there is no risk for the moment because the avatar is renamed to avatar_upload on the remote server , but it ll be nice to secure this part of code .
Example
here is the same file with two different extension :
http://91.121.108.101/image1.jpg http://91.121.108.101/image1.php <== execute php code inside the image
-
download image1.jpg
-
as you can see if you open the file image1.jpg file on notepad it hide php code ( phpinfo(); function in this case .
-
rename image1.jpg to image1.php , and try to upload it on the avatar upload form , it pass the verification .
This verification is not enought in this file : /core/controller/avatarcontroller.php
if ($image->valid()) {
$mimeType = $image->mimeType();
if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
return new DataResponse(
['data' => ['message' => $this->l->t('Unknown filetype')]],
Http::STATUS_OK,
$headers
);
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the upload validation relies solely on the MIME type returned by the image library, without checking the file extension or content, allowing a PHP file with a valid image header to pass.
Impact
An attacker could upload a PHP file disguised as an image, but the report states there is no risk for the moment because the avatar is renamed on the remote server, preventing execution.
What the attacker needed
Access to the avatar upload form
The fix
The upload verification should be strengthened to secure this part of the code.
How it was found
- Download the provided image file that contains hidden PHP code.
- Open the image in a text editor to see the embedded PHP code.
- Rename the image file to have a .php extension.
- Upload the renamed file through the avatar upload form, which accepts it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you upload a picture, the website should check what the file really is, not just what it claims to be. Here, the site only looked at the file's type label, so someone could rename a PHP script to look like a picture and upload it. PHP is a programming language that runs on the server, so if the file were executed it could run code.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.