From 56d5af1336d863412f715d462696b006457ee324 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Thu, 7 Dec 2017 19:46:25 +0000 Subject: [PATCH] Made it possible to configure proxies via env In reference to #146 --- app/Http/Middleware/TrustProxies.php | 18 ++++++++++++++++++ config/app.php | 2 ++ 2 files changed, 20 insertions(+) diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 69fcbe943..c3102571d 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -2,6 +2,7 @@ namespace BookStack\Http\Middleware; +use Closure; use Illuminate\Http\Request; use Fideloper\Proxy\TrustProxies as Middleware; @@ -26,4 +27,21 @@ class TrustProxies extends Middleware Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT', Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO', ]; + + /** + * Handle the request, Set the correct user-configured proxy information. + * @param Request $request + * @param Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + $setProxies = config('app.proxies'); + if ($setProxies !== '**' && $setProxies !== '*' && $setProxies !== '') { + $setProxies = explode(',', $setProxies); + } + $this->proxies = $setProxies; + + return parent::handle($request, $next); + } } diff --git a/config/app.php b/config/app.php index d8def5c95..3be50b6c5 100755 --- a/config/app.php +++ b/config/app.php @@ -234,4 +234,6 @@ return [ ], + 'proxies' => env('APP_PROXIES', ''), + ];