diff --git a/src/Http/Middleware/NonWWW.php b/src/Http/Middleware/NonWWW.php index bece26c..cc37589 100644 --- a/src/Http/Middleware/NonWWW.php +++ b/src/Http/Middleware/NonWWW.php @@ -3,6 +3,7 @@ namespace ReliqArts\Http\Middleware; use Closure; +use Symfony\Component\HttpFoundation\Request; /** * Redirects any www requests to non-www counterparts. @@ -14,10 +15,17 @@ */ class NonWWW { + private const TRUSTED_PROXY_HEADERS = Request::HEADER_X_FORWARDED_FOR | + Request::HEADER_X_FORWARDED_HOST | + Request::HEADER_X_FORWARDED_PORT | + Request::HEADER_X_FORWARDED_PROTO | + Request::HEADER_X_FORWARDED_PREFIX | + Request::HEADER_X_FORWARDED_AWS_ELB; + public function handle($request, Closure $next) { if (str_starts_with($request->header('host'), 'www.')) { - $request->setTrustedProxies([$request->getClientIp()], config('trustedproxy.headers')); + $request->setTrustedProxies([$request->getClientIp()], self::TRUSTED_PROXY_HEADERS); $request->headers->set('host', parse_url(config('app.url'), PHP_URL_HOST)); return redirect($request->getRequestUri(), 301);