Skip to content

Commit

Permalink
Merge pull request #61 from Laravel-Backpack/prevent-mimetypes-tampering
Browse files Browse the repository at this point in the history
Prevent mimetypes tampering
  • Loading branch information
pxpm authored Nov 18, 2024
2 parents d317f5c + b6d85c9 commit e28eb6e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/elfinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/

'route' => [
'prefix' => config('backpack.base.route_prefix', 'admin').'/elfinder',
'prefix' => config('backpack.base.route_prefix', 'admin').'/elfinder',
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')], //Set to null to disable middleware filter
],

Expand Down
38 changes: 38 additions & 0 deletions src/BackpackElfinderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Backpack\FileManager;

use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;

class BackpackElfinderController extends \Barryvdh\Elfinder\ElfinderController
{
public function showPopup($input_id)
{
$mimes = request('mimes');

if (! isset($mimes)) {
Log::error('Someone attempted to tamper with mime types in elfinder popup. The attempt was blocked.');
abort(403, 'Unauthorized action.');
}

try {
$mimes = Crypt::decrypt(urldecode(request('mimes')));
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
Log::error('Someone attempted to tamper with mime types in elfinder popup. The attempt was blocked.');
abort(403, 'Unauthorized action.');
}

request()->merge(['mimes' => urlencode(serialize($mimes))]);
if (! empty($mimes)) {
request()->merge(['mimes' => urlencode(serialize($mimes))]);
} else {
request()->merge(['mimes' => '']);
}

return $this->app['view']
->make($this->package.'::standalonepopup')
->with($this->getViewVars())
->with(compact('input_id'));
}
}
10 changes: 8 additions & 2 deletions src/FileManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Backpack\FileManager;

use Barryvdh\Elfinder\ElfinderController;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

Expand All @@ -27,6 +28,11 @@ public function boot()
}
}

public function register()
{
$this->app->bind(ElfinderController::class, BackpackElfinderController::class);
}

/**
* Console-specific booting.
*
Expand All @@ -40,11 +46,11 @@ protected function bootForConsole()
], 'views');

$this->publishes([
__DIR__.'/../config/elfinder.php' => config_path('elfinder.php'),
__DIR__.'/../config/elfinder.php' => config_path('elfinder.php'),
], 'config');

$this->publishes([
__DIR__.'/../public/packages/backpack/filemanager/themes/Backpack' => public_path('packages/backpack/filemanager/themes/Backpack'),
__DIR__.'/../public/packages/backpack/filemanager/themes/Backpack' => public_path('packages/backpack/filemanager/themes/Backpack'),
], 'public');

// Registering package commands.
Expand Down

0 comments on commit e28eb6e

Please sign in to comment.