Skip to content

Commit 89c67e6

Browse files
committed
Security: Add MIME type validation for image uploads in ck_uploadimage action
1 parent 8bd8691 commit 89c67e6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

main/inc/ajax/document.ajax.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
/**
55
* Responses to AJAX calls for the document upload.
66
*/
7+
8+
use Chamilo\CoreBundle\Component\Editor\Driver\Driver;
9+
710
require_once __DIR__.'/../global.inc.php';
811

912
$action = $_REQUEST['a'];
@@ -199,6 +202,10 @@
199202
}
200203
break;
201204
case 'ck_uploadimage':
205+
if (true !== api_get_configuration_value('enable_uploadimage_editor')) {
206+
exit;
207+
}
208+
202209
api_protect_course_script(true);
203210

204211
// it comes from uploaimage drag and drop ckeditor
@@ -210,6 +217,14 @@
210217

211218
$data = [];
212219
$fileUpload = $_FILES['upload'];
220+
$mimeType = mime_content_type($fileUpload['tmp_name']);
221+
222+
$isMimeAccepted = (new Driver())->mimeAccepted($mimeType, ['image']);
223+
224+
if (!$isMimeAccepted) {
225+
exit;
226+
}
227+
213228
$isAllowedToEdit = api_is_allowed_to_edit(null, true);
214229
if ($isAllowedToEdit) {
215230
$globalFile = ['files' => $fileUpload];
@@ -249,7 +264,11 @@
249264
$suffix = '_'.uniqid();
250265
$fileUploadName = $fileName.$suffix.'.'.$extension;
251266
}
252-
if (!move_uploaded_file($fileUpload['tmp_name'], $syspath . $fileUploadName)) {
267+
268+
$personalDriver = new PersonalDriver();
269+
$uploadResult = $personalDriver->mimeAccepted(mime_content_type($fileUpload['tmp_name']), ['image']);
270+
271+
if (!$uploadResult || !move_uploaded_file($fileUpload['tmp_name'], $syspath . $fileUploadName)) {
253272
exit;
254273
}
255274

0 commit comments

Comments
 (0)