Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit b2126e1

Browse files
committed
a couple of vulnerabilities were detected
- Server-Side Request Forgery (SSRF) in Upload image from URL. "CVE-2021-27566" - Bypass Unrestricted File Upload. "CVE-2021-27567"
1 parent 7bc3ad5 commit b2126e1

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
+ using the upload panel
8686
+ drag & drop anywhere
8787
+ click & hold on an empty area **"items container"**
88-
+ from a url
88+
+ from a url **"images only"**
8989
- [preview files before uploading](https://github.com/ctf0/Laravel-Media-Manager/wiki/Preview-Files-Before-Uploading)
9090
- toggle between `random/original` names for uploaded files
9191
- [asynchronous Updates](https://github.com/ctf0/Laravel-Media-Manager/wiki/Async-Update-The-Manager)

src/App/Controllers/MediaController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class MediaController extends Controller
4242
protected $storageDisk;
4343
protected $storageDiskInfo;
4444
protected $unallowedMimes;
45+
protected $unallowedExt;
4546

4647
public function __construct()
4748
{
@@ -53,6 +54,7 @@ public function __construct()
5354
$this->folderChars = $config['allowed_folderNames_chars'];
5455
$this->sanitizedText = $config['sanitized_text'];
5556
$this->unallowedMimes = $config['unallowed_mimes'];
57+
$this->unallowedExt = $config['unallowed_ext'];
5658
$this->LMF = $config['last_modified_format'];
5759
$this->GFI = $config['get_folder_info'] ?? true;
5860
$this->paginationAmount = $config['pagination_amount'] ?? 50;

src/App/Controllers/Modules/Upload.php

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ public function upload(Request $request)
4343
// check for mime type
4444
if (Str::contains($file_type, $this->unallowedMimes)) {
4545
throw new Exception(
46-
trans('MediaManager::messages.not_allowed_file_ext', ['attr' => $file_type])
46+
trans('MediaManager::messages.not_allowed_file_ext')
47+
);
48+
}
49+
50+
// check for extension
51+
if (Str::contains($ext_only, $this->unallowedExt)) {
52+
throw new Exception(
53+
trans('MediaManager::messages.not_allowed_file_ext')
4754
);
4855
}
4956

@@ -59,9 +66,9 @@ public function upload(Request $request)
5966

6067
// fire event
6168
event('MMFileUploaded', [
62-
'file_path' => $full_path,
63-
'mime_type' => $file_type,
64-
'options' => $file_options,
69+
'file_path' => $full_path,
70+
'mime_type' => $file_type,
71+
'options' => $file_options,
6572
]);
6673

6774
$broadcast = true;
@@ -122,8 +129,17 @@ public function uploadEditedImage(Request $request)
122129
);
123130
}
124131

132+
// data is valid
133+
try {
134+
$data = base64_decode($data);
135+
} catch (\Throwable $th) {
136+
throw new Exception(
137+
trans('MediaManager::messages.error.no_file')
138+
);
139+
}
140+
125141
// save file
126-
$this->storageDisk->put($destination, base64_decode($data));
142+
$this->storageDisk->put($destination, $data);
127143

128144
// fire event
129145
event('MMFileSaved', [
@@ -182,10 +198,12 @@ public function uploadLink(Request $request)
182198
$file_type = image_type_to_mime_type(@exif_imagetype($url));
183199

184200
try {
201+
$ignore = array_merge($this->unallowedMimes, ['application/octet-stream']);
202+
185203
// check for mime type
186-
if (Str::contains($file_type, $this->unallowedMimes)) {
204+
if (Str::contains($file_type, $ignore)) {
187205
throw new Exception(
188-
trans('MediaManager::messages.not_allowed_file_ext', ['attr' => $file_type])
206+
trans('MediaManager::messages.not_allowed_file_ext')
189207
);
190208
}
191209

@@ -196,8 +214,17 @@ public function uploadLink(Request $request)
196214
);
197215
}
198216

217+
// data is valid
218+
try {
219+
$data = file_get_contents($url);
220+
} catch (\Throwable $th) {
221+
throw new Exception(
222+
trans('MediaManager::messages.error.no_file')
223+
);
224+
}
225+
199226
// save file
200-
$this->storageDisk->put($destination, file_get_contents($url));
227+
$this->storageDisk->put($destination, $data);
201228

202229
// fire event
203230
event('MMFileSaved', [
@@ -218,7 +245,7 @@ public function uploadLink(Request $request)
218245
} catch (Exception $e) {
219246
$result = [
220247
'success' => false,
221-
'message' => "\"$file_name\" " . $e->getMessage(),
248+
'message' => $e->getMessage(),
222249
];
223250
}
224251
} else {

src/config/mediaManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
*/
4646
'unallowed_mimes' => ['php', 'java'],
4747

48+
/*
49+
* disallow uploading files with the following extensions
50+
* https://en.wikipedia.org/wiki/List_of_filename_extensions
51+
*/
52+
'unallowed_ext' => ['php', 'jav', 'py'],
53+
4854
/*
4955
* extra mime-types
5056
*/

src/resources/lang/en/messages.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
'moving' => 'There Seems To Be A Problem Moving This File/Folder, Make Sure You Have The Correct Permissions',
118118
'moving_cloud' => 'Cloud Folders Can\'t Be "Renamed, Moved Or Copied"',
119119
'move_into_self' => 'Folder Can\'t Be "Moved Or Copied" Into It Self',
120+
'no_file' => 'No File To Upload',
120121
],
121122
'filter' => [
122123
'main' => 'Filter',
@@ -153,7 +154,7 @@
153154
'no_files_in_folder' => 'No Files In This Folder',
154155
'no_val' => 'Maybe You Should Add Something First !!!',
155156
'non' => 'Non',
156-
'not_allowed_file_ext' => 'Files Of Type ":attr" Are Not Allowed',
157+
'not_allowed_file_ext' => 'File Type Is Not Allowed',
157158
'nothing_found' => 'Nothing Found',
158159
'open' => 'Open',
159160
'pdf' => 'Your Browser Does Not Support Pdfs, Please Download The Pdf To View It',

0 commit comments

Comments
 (0)