Skip to content

Commit

Permalink
fix: security issue with image upload (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite authored Mar 1, 2024
1 parent 33a39c7 commit 7b5e166
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion endpoints/payments/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function saveLogo($imageData, $uploadFile, $name) {
}
}

function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) { $targetWidth = 70;
function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
$targetWidth = 70;
$targetHeight = 48;

$timestamp = time();
Expand Down Expand Up @@ -154,6 +155,15 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) { $targetW
$icon = getLogoFromUrl($iconUrl, '../../images/uploads/logos/', $name);
} else {
if (!empty($_FILES['paymenticon']['name'])) {
$fileType = mime_content_type($_FILES['paymenticon']['tmp_name']);
if (strpos($fileType, 'image') === false) {
$response = [
"success" => false,
"errorMessage" => translate('fill_all_fields', $i18n)
];
echo json_encode($response);
exit();
}
$icon = resizeAndUploadLogo($_FILES['paymenticon'], '../../images/uploads/logos/', $name);
}
}
Expand Down
5 changes: 5 additions & 0 deletions endpoints/subscription/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
$logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name);
} else {
if (!empty($_FILES['logo']['name'])) {
$fileType = mime_content_type($_FILES['logo']['tmp_name']);
if (strpos($fileType, 'image') === false) {
echo translate("fill_all_fields", $i18n);
exit();
}
$logo = resizeAndUploadLogo($_FILES['logo'], '../../images/uploads/logos/', $name);
}
}
Expand Down

0 comments on commit 7b5e166

Please sign in to comment.