From: TehPeGaSuS <25697531+TehPeGaSuS@users.noreply.github.com> Date: Sun, 25 Oct 2026 22:45:56 +0000 (+0100) Subject: Accept a leading dot in disallowed_extensions entries X-Git-Tag: 4.8.0~11^2~2 X-Git-Url: https://git.p6c8.net/jirafeau/jirafeau.git/commitdiff_plain/2f4863be910a200d704a23dec421063e604dd565 Accept a leading dot in disallowed_extensions entries --- diff --git a/index.php b/index.php index 402e784..4384867 100644 --- a/index.php +++ b/index.php @@ -137,7 +137,7 @@ elseif (true === jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) { echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB."; } ?>'); control_selected_file_extension(, '.')"/>

@@ -187,7 +187,7 @@ if ($cfg['maximal_upload_size'] >= 1024) { echo '

'; } if (!empty($cfg['disallowed_extensions'])) { - echo '

' . t('EXT_LIM') . ' ' . implode(', ', $cfg['disallowed_extensions']) . '

'; + echo '

' . t('EXT_LIM') . ' ' . implode(', ', jirafeau_disallowed_extensions($cfg)) . '

'; } ?> diff --git a/lib/config.original.php b/lib/config.original.php index e140067..54be072 100644 --- a/lib/config.original.php +++ b/lib/config.original.php @@ -172,7 +172,7 @@ $cfg['maximal_upload_size'] = 0; /* Forbid specific file extensions from being uploaded. * Leave empty to allow every extension. - * Extensions are matched case-insensitively and without the leading dot. + * Extensions are matched case-insensitively; a leading dot is optional. * Compound extensions such as 'tar.gz' are supported. Note that 'gz' * also covers 'tar.gz', while 'tar.gz' leaves plain '.gz' files allowed. * $cfg['disallowed_extensions'] = array('exe', 'bat', 'sh', 'php', 'tar.gz'); diff --git a/lib/functions.php b/lib/functions.php index 3e9155f..7f03b5f 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -229,6 +229,30 @@ function jirafeau_ini_to_bytes($value) return $bytes; } +/** + * returns the configured disallowed extensions, lower-cased and without + * a leading dot + * @param $cfg jirafeau config + * @returns array of normalized extensions + */ +function jirafeau_disallowed_extensions($cfg) +{ + if (empty($cfg['disallowed_extensions'])) { + return array(); + } + + // tolerate a leading dot in the config, e.g. '.jpg' instead of 'jpg' + $extensions = array(); + foreach ($cfg['disallowed_extensions'] as $extension) { + $extension = ltrim(strtolower(trim($extension)), '.'); + if ($extension !== '') { + $extensions[] = $extension; + } + } + + return $extensions; +} + /** * checks if a file name's extension is allowed to be uploaded * @param $cfg jirafeau config @@ -237,7 +261,8 @@ function jirafeau_ini_to_bytes($value) */ function jirafeau_is_extension_allowed($cfg, $filename) { - if (empty($cfg['disallowed_extensions'])) { + $extensions = jirafeau_disallowed_extensions($cfg); + if (empty($extensions)) { return true; } @@ -246,8 +271,8 @@ function jirafeau_is_extension_allowed($cfg, $filename) // suffix match so that compound extensions such as 'tar.gz' work too; // 'gz' still covers 'archive.tar.gz' - foreach ($cfg['disallowed_extensions'] as $extension) { - $suffix = '.' . strtolower($extension); + foreach ($extensions as $extension) { + $suffix = '.' . $extension; if (substr($filename, -strlen($suffix)) === $suffix) { return false; }