I can bypass an avatar upload image verification process and upload a PHP file or any other extension binding a valid jpeg image.
This is the code:
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
);
}
For example:
download image1.jpg
as you can see if you open the file image1.jpg file on notepad it hides PHP code
( phpinfo();
function in this case.rename image1.jpg to image1.php, and try to upload it on the avatar upload form. It passes verification.
How to secure this code?