Skip to content

Commit 3b1cc1c

Browse files
authored
Merge pull request from GHSA-g872-jwwr-vggm
implement check for filename and file extension
2 parents 045a23a + 4454be9 commit 3b1cc1c

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

adm_program/modules/messages/messages_send.php

+22-13
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,29 @@
273273
}
274274

275275
if ($_FILES['userfile']['error'][$currentAttachmentNo] === UPLOAD_ERR_OK) {
276-
// check the size of the attachment
277-
$attachmentSize += $_FILES['userfile']['size'][$currentAttachmentNo];
278-
if ($attachmentSize > Email::getMaxAttachmentSize()) {
279-
$gMessage->show($gL10n->get('SYS_ATTACHMENT_TO_LARGE'));
280-
// => EXIT
281-
}
282-
283-
// set file type to standard if not given
284-
if (strlen($_FILES['userfile']['type'][$currentAttachmentNo]) <= 0) {
285-
$_FILES['userfile']['type'][$currentAttachmentNo] = 'application/octet-stream';
286-
}
287-
288-
// add the attachment to the email and message object
289276
try {
277+
// check filename and throw exception if something is wrong
278+
StringUtils::strIsValidFileName($_FILES['userfile']['name'][$currentAttachmentNo], false);
279+
280+
// check for valid file extension of attachment
281+
if(!FileSystemUtils::allowedFileExtension($_FILES['userfile']['name'][$currentAttachmentNo])) {
282+
$gMessage->show($gL10n->get('SYS_FILE_EXTENSION_INVALID'));
283+
// => EXIT
284+
}
285+
286+
// check the size of the attachment
287+
$attachmentSize += $_FILES['userfile']['size'][$currentAttachmentNo];
288+
if ($attachmentSize > Email::getMaxAttachmentSize()) {
289+
$gMessage->show($gL10n->get('SYS_ATTACHMENT_TO_LARGE'));
290+
// => EXIT
291+
}
292+
293+
// set file type to standard if not given
294+
if (strlen($_FILES['userfile']['type'][$currentAttachmentNo]) <= 0) {
295+
$_FILES['userfile']['type'][$currentAttachmentNo] = 'application/octet-stream';
296+
}
297+
298+
// add the attachment to the email and message object
290299
$email->addAttachment($_FILES['userfile']['tmp_name'][$currentAttachmentNo], $_FILES['userfile']['name'][$currentAttachmentNo], $encoding = 'base64', $_FILES['userfile']['type'][$currentAttachmentNo]);
291300
$message->addAttachment($_FILES['userfile']['tmp_name'][$currentAttachmentNo], $_FILES['userfile']['name'][$currentAttachmentNo]);
292301
} catch (Exception $e) {

0 commit comments

Comments
 (0)