]> git.p6c8.net - jirafeau/pcanterino.git/commitdiff
Match compound extensions such as tar.gz in disallowed_extensions
authorTehPeGaSuS <25697531+TehPeGaSuS@users.noreply.github.com>
Mon, 19 Oct 2026 19:04:17 +0000 (21:04 +0200)
committerTehPeGaSuS <25697531+TehPeGaSuS@users.noreply.github.com>
Mon, 19 Oct 2026 19:04:17 +0000 (21:04 +0200)
lib/config.original.php
lib/functions.js.php
lib/functions.php

index 2be4e52bdb0d51476494f1d6f9d0a938cb8dce32..e140067271180b849c45fe29e8dbc4cd7ef3885d 100644 (file)
@@ -173,7 +173,9 @@ $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.
- * $cfg['disallowed_extensions'] = array('exe', 'bat', 'sh', 'php');
+ * 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');
  */
 $cfg['disallowed_extensions'] = array();
 
index efa82e5a3ff52dccbc89804b02322fa297d50082..65febf178f49b9b81ecb1904cc925f851b12bf45 100644 (file)
@@ -356,9 +356,9 @@ 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.replace(/[\s.]+$/, '');
-    f_ext = f_name.includes('.') ? f_name.split('.').pop().toLowerCase() : '';
-    if (disallowed_extensions.includes(f_ext))
+    f_name = document.getElementById('file_select').files[0].name.replace(/[\s.]+$/, '').toLowerCase();
+    // suffix match so that compound extensions such as 'tar.gz' work too
+    if (disallowed_extensions.some(function (ext) { return f_name.endsWith('.' + ext); }))
     {
         // control_selected_file_size runs first: keep its error, if any, and add ours
         var error_pop = document.getElementById('error_pop');
index 60902480350236dfea3c3f563843818742d8c76c..2d59cd325acb0dd2e756d9ec792fec51b3755fe7 100644 (file)
@@ -242,11 +242,18 @@ function jirafeau_is_extension_allowed($cfg, $filename)
     }
 
     // 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']);
+    $filename = strtolower(rtrim($filename, " \t\n\r\0\x0B."));
 
-    return !in_array($extension, $disallowed);
+    // 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);
+        if (substr($filename, -strlen($suffix)) === $suffix) {
+            return false;
+        }
+    }
+
+    return true;
 }
 
 /**

patrick-canterino.de