From 44f7fbb13eabc0d1571455b3e68a812a617c3691 Mon Sep 17 00:00:00 2001 From: Armin Preiml Date: Mon, 29 Feb 2016 16:27:20 +0100 Subject: [PATCH 1/5] validate log file path --- .../LaravelLogViewer/LaravelLogViewer.php | 23 +++++++++++++------ src/controllers/LogViewerController.php | 15 ++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index d41ef63..7470e9f 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -46,18 +46,27 @@ class LaravelLogViewer */ public static function setFile($file) { - // if absolute path is given + $file = self::pathToLogFile($file); + if (File::exists($file)) { self::$file = $file; + } + } + + public static function pathToLogFile($file) + { + $logsPath = storage_path('logs'); - // or check if file with given filename is in storage/logs folder - } else { - $file = storage_path() . '/logs/' . $file; + if (! File::exists($file)) { // try the absolute path + $file = $logsPath . '/' . $file; + } - if (File::exists($file)) { - self::$file = $file; - } + // check if requested file is really in the logs directory + if (dirname($file) !== $logsPath) { + throw new \Exception('No such log file'); } + + return $file; } /** diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php index ca580da..20ff21f 100644 --- a/src/controllers/LogViewerController.php +++ b/src/controllers/LogViewerController.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Response; +use Input; class LogViewerController extends Controller @@ -14,14 +15,15 @@ class LogViewerController extends Controller public function index() { - if (Request::input('l')) { - LaravelLogViewer::setFile(base64_decode(Request::input('l'))); + + if (Input::get('l')) { + LaravelLogViewer::setFile(base64_decode(Input::get('l'))); } - if (Request::input('dl')) { - return Response::download(storage_path() . '/logs/' . base64_decode(Request::input('dl'))); - } elseif (Request::has('del')) { - File::delete(storage_path() . '/logs/' . base64_decode(Request::input('del'))); + if (Input::get('dl')) { + return Response::download(LaravelLogViewer::pathToLogFile(base64_decode(Input::get('dl')))); + } elseif (Input::has('del')) { + File::delete(LaravelLogViewer::pathToLogFile(base64_decode(Input::get('del')))); return Redirect::to(Request::url()); } @@ -33,5 +35,4 @@ public function index() 'current_file' => LaravelLogViewer::getFileName() ]); } - } From 8c8d96c0a7df1b6762ecc0e6a1a32336a05a6890 Mon Sep 17 00:00:00 2001 From: Armin Preiml Date: Mon, 29 Feb 2016 16:41:10 +0100 Subject: [PATCH 2/5] enforce https for js cdn urls --- src/views/log.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/log.blade.php b/src/views/log.blade.php index 3e2e81d..1f497ae 100644 --- a/src/views/log.blade.php +++ b/src/views/log.blade.php @@ -8,7 +8,7 @@ - + @@ -98,8 +98,8 @@ - - + +