Skip to content

Commit 9e90227

Browse files
committed
security: prevent executables from being uploaded
1 parent 908ff8e commit 9e90227

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/LfmPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function validateUploadedFile($file)
253253
$validator->nameIsNotDuplicate($this->getNewName($file), $this);
254254
}
255255

256-
$validator->isNotExcutable();
256+
$validator->isNotExcutable(config('lfm.disallowed_mimetypes', ['text/x-php', 'text/html', 'text/plain']));
257257

258258
if (config('lfm.should_validate_mime', false)) {
259259
$validator->mimeTypeIsValid($this->helper->availableMimeTypes());

src/LfmUploadValidator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ public function nameIsNotDuplicate($new_file_name, LfmPath $lfm_path)
6161
return $this;
6262
}
6363

64-
public function isNotExcutable()
64+
public function isNotExcutable($excutable_mimetypes)
6565
{
6666
$mimetype = $this->file->getMimeType();
6767

68-
$excutable = ['text/x-php'];
69-
70-
if (in_array($mimetype, $excutable)) {
68+
if (in_array($mimetype, $excutable_mimetypes)) {
7169
throw new ExcutableFileException();
7270
}
7371

src/config/lfm.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113
// setting it to false show `error-file-exist` error and stop upload
114114
'over_write_on_duplicate' => false,
115115

116+
// mimetypes of executables to prevent from uploading
117+
'disallowed_mimetypes' => ['text/x-php', 'text/html', 'text/plain'],
118+
116119
// Item Columns
117120
'item_columns' => ['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url'],
118121

0 commit comments

Comments
 (0)