Skip to content

Commit 9cfe126

Browse files
committed
FIX Force downlaod of file with .noexe as octet-stream mime type
1 parent b5c5cc4 commit 9cfe126

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

htdocs/document.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ function llxFooter()
159159
$type = 'application/octet-stream';
160160
if (GETPOST('type', 'alpha')) $type=GETPOST('type', 'alpha');
161161
else $type=dol_mimetype($original_file);
162+
// Security: Force to octet-stream if file is a dangerous file
163+
if (preg_match('/\.noexe$/i', $original_file)) $type = 'application/octet-stream';
162164

163165
// Security: Delete string ../ into $original_file
164166
$original_file = str_replace("../", "/", $original_file);
@@ -215,7 +217,7 @@ function llxFooter()
215217
}
216218

217219
// Security:
218-
// On interdit les remontees de repertoire ainsi que les pipe dans les noms de fichiers.
220+
// We refuse directory transversal change and pipes in file names
219221
if (preg_match('/\.\./', $fullpath_original_file) || preg_match('/[<>|]/', $fullpath_original_file))
220222
{
221223
dol_syslog("Refused to deliver file ".$fullpath_original_file);
@@ -227,6 +229,7 @@ function llxFooter()
227229
clearstatcache();
228230

229231
$filename = basename($fullpath_original_file);
232+
$filename = preg_replace('/\.noexe$/i', '', $filename);
230233

231234
// Output file on browser
232235
dol_syslog("document.php download $fullpath_original_file filename=$filename content-type=$type");

0 commit comments

Comments
 (0)