Check for mimetype during template upload

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-08-20 08:56:57 +02:00
Родитель e414e0c840
Коммит db417fe8f7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
2 изменённых файлов: 23 добавлений и 7 удалений

Просмотреть файл

@ -135,6 +135,13 @@ class TemplatesController extends Controller {
);
}
if (!$this->manager->isValidTemplateMime($files['type'][0])) {
return new JSONResponse(
['data' => ['message' => $this->l10n->t('Only template files can be uploaded')]],
Http::STATUS_BAD_REQUEST
);
}
$templateName = $files['name'][0];
$templateFile = file_get_contents($files['tmp_name'][0]);

Просмотреть файл

@ -203,13 +203,7 @@ class TemplateManager {
return false;
}
if ($type !== null && !in_array($templateFile->getMimeType(), self::$tplTypes[$type])) {
return false;
}
//Todo validate mimetypes etc
return true;
return $this->isValidTemplateMime($templateFile->getMimeType(), $type);
});
}
@ -489,4 +483,19 @@ class TemplateManager {
'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
];
}
public function isValidTemplateMime($mime, $type = null) {
if ($type === null) {
$allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation']);
if (!in_array($mime, $allMimes)) {
return false;
}
}
if ($type !== null && !in_array($mime, self::$tplTypes[$type])) {
return false;
}
return true;
}
}