Skip to content

Commit

Permalink
prevent mime type tampering
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Nov 18, 2024
1 parent d317f5c commit f8b8085
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
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'));
}
}
6 changes: 6 additions & 0 deletions src/FileManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

class FileManagerServiceProvider extends ServiceProvider
{
Expand All @@ -27,6 +28,11 @@ public function boot()
}
}

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

/**
* Console-specific booting.
*
Expand Down

0 comments on commit f8b8085

Please sign in to comment.