]> git.p6c8.net - jirafeau/jirafeau.git/commitdiff
Ignore trailing dots and whitespace when checking file extension
authorTehPeGaSuS <25697531+TehPeGaSuS@users.noreply.github.com>
Fri, 16 Oct 2026 10:38:32 +0000 (12:38 +0200)
committerTehPeGaSuS <25697531+TehPeGaSuS@users.noreply.github.com>
Fri, 16 Oct 2026 10:51:25 +0000 (12:51 +0200)
lib/functions.js.php
lib/functions.php

index 656108b7cb69809a41aa34b6f800f115203d5450..9307eda582a2fd8e899563cb2331e42797a39a3b 100644 (file)
@@ -356,7 +356,7 @@ function control_selected_file_size(max_size, error_str)
 // just warns the user before they submit a doomed upload.
 function control_selected_file_extension(disallowed_extensions, error_str)
 {
-    f_name = document.getElementById('file_select').files[0].name;
+    f_name = document.getElementById('file_select').files[0].name.replace(/[\s.]+$/, '');
     f_ext = f_name.includes('.') ? f_name.split('.').pop().toLowerCase() : '';
     if (disallowed_extensions.includes(f_ext))
     {
index 8bfa61bb3482d6993ab0dee22c8f7643a9923a17..60902480350236dfea3c3f563843818742d8c76c 100644 (file)
@@ -241,6 +241,8 @@ function jirafeau_is_extension_allowed($cfg, $filename)
         return true;
     }
 
+    // trailing dots and whitespace are dropped on storage or by the client OS
+    $filename = rtrim($filename, " \t\n\r\0\x0B.");
     $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
     $disallowed = array_map('strtolower', $cfg['disallowed_extensions']);
 

patrick-canterino.de