Skip to content

Commit f8b8085

Browse files
committed
prevent mime type tampering
1 parent d317f5c commit f8b8085

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/BackpackElfinderController.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Backpack\FileManager;
4+
5+
use Illuminate\Support\Facades\Crypt;
6+
use Illuminate\Support\Facades\Log;
7+
8+
class BackpackElfinderController extends \Barryvdh\Elfinder\ElfinderController
9+
{
10+
public function showPopup($input_id)
11+
{
12+
$mimes = request('mimes');
13+
14+
if (! isset($mimes)) {
15+
Log::error('Someone attempted to tamper with mime types in elfinder popup. The attempt was blocked.');
16+
abort(403, 'Unauthorized action.');
17+
}
18+
19+
try {
20+
$mimes = Crypt::decrypt(urldecode(request('mimes')));
21+
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
22+
Log::error('Someone attempted to tamper with mime types in elfinder popup. The attempt was blocked.');
23+
abort(403, 'Unauthorized action.');
24+
}
25+
26+
request()->merge(['mimes' => urlencode(serialize($mimes))]);
27+
if (! empty($mimes)) {
28+
request()->merge(['mimes' => urlencode(serialize($mimes))]);
29+
} else {
30+
request()->merge(['mimes' => '']);
31+
}
32+
33+
return $this->app['view']
34+
->make($this->package.'::standalonepopup')
35+
->with($this->getViewVars())
36+
->with(compact('input_id'));
37+
}
38+
}

src/FileManagerServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\ServiceProvider;
7+
use Barryvdh\Elfinder\ElfinderController;
78

89
class FileManagerServiceProvider extends ServiceProvider
910
{
@@ -27,6 +28,11 @@ public function boot()
2728
}
2829
}
2930

31+
public function register()
32+
{
33+
$this->app->bind(ElfinderController::class, BackpackElfinderController::class);
34+
}
35+
3036
/**
3137
* Console-specific booting.
3238
*

0 commit comments

Comments
 (0)