Skip to content

Commit

Permalink
fix: [security] properly check for valid logo upload
Browse files Browse the repository at this point in the history
- as kindly reported by Rémi Matasse and Raphael Lob from Synacktiv (https://www.synacktiv.com)
  • Loading branch information
iglocska committed Mar 5, 2024
1 parent 238010b commit 6a2986b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/Controller/OrganisationsController.php
Expand Up @@ -490,8 +490,14 @@ private function __uploadLogo($orgId)
$this->Flash->error(__('Invalid file extension, Only PNG and SVG images are allowed.'));
return false;
}

$imgMime = mime_content_type($logo['tmp_name']);
$matches = null;
$tmp_name = $logo['tmp_name'];
if (preg_match_all('/[\w\/\-\.]*/', $tmp_name, $matches) && file_exists($logo['tmp_name'])) {
$tmp_name = $matches[0][0];
$imgMime = mime_content_type($tmp_name);
} else {
throw new NotFoundException(__('Invalid file.'));
}
if ($extension === 'png' && (function_exists('exif_imagetype') && !exif_imagetype($logo['tmp_name']))) {
$this->Flash->error(__('This is not a valid PNG image.'));
return false;
Expand All @@ -507,8 +513,8 @@ private function __uploadLogo($orgId)
return false;
}

if (!empty($logo['tmp_name']) && is_uploaded_file($logo['tmp_name'])) {
return move_uploaded_file($logo['tmp_name'], APP . 'files/img/orgs/' . $filename);
if (!empty($tmp_name) && is_uploaded_file($tmp_name)) {
return move_uploaded_file($tmp_name, APP . 'files/img/orgs/' . $filename);
}
}

Expand Down

0 comments on commit 6a2986b

Please sign in to comment.