diff --git a/lib/functions.php b/lib/functions.php index a6b8f6d817331650b788fbe080cc63612dc46c3b..c4ff703ff465ca6aada45242043479f05a00d53b 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1702,12 +1702,9 @@ function rmdirr($dirname){ /** - * Determines an appropriate MIME type for a file based on the - * extension of the file name. - * - * @param string $filename file name to check + * Returns the mapping of extensions to supported MIME types. */ -function get_mime_type($filename) +function get_mime_types() { static $mime_types = [ // archive types @@ -1761,6 +1758,19 @@ function get_mime_type($filename) 'webm' => 'video/webm', ]; + return $mime_types; +} + + +/** + * Determines an appropriate MIME type for a file based on the + * extension of the file name. + * + * @param string $filename file name to check + */ +function get_mime_type($filename) +{ + $mime_types = get_mime_types(); $extension = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if (isset($mime_types[$extension])) { diff --git a/public/sendfile.php b/public/sendfile.php index 5485ca297e69ea590df91c810649d79fb6c275a1..80084083c2c6a5621128367a52c2bd99bf032bc1 100644 --- a/public/sendfile.php +++ b/public/sendfile.php @@ -186,16 +186,9 @@ if (!file_exists($path_file)) { throw new Exception(_('Fehler beim Laden der Inhalte der Datei')); } -$content_blacklisted = function ($mime) { - foreach (['html', 'javascript', 'svg', 'xml'] as $check) { - if (stripos($mime, $check) !== false) { - return true; - } - } - return false; -}; +$allowed_mime_types = get_mime_types(); -if ($content_blacklisted($content_type)) { +if (!in_array($content_type, $allowed_mime_types)) { $content_type = 'application/octet-stream'; } if (Request::int('force_download') || $content_type == "application/octet-stream") {