fix: add middleware for TrustHosts/Proxies

This commit is contained in:
Phan An 2024-07-16 21:27:45 +02:00
parent 3f4b887c6a
commit 6fc069eb91
3 changed files with 24 additions and 3 deletions

View file

@ -14,8 +14,10 @@ use App\Http\Middleware\VerifyCsrfToken;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance;
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
use Illuminate\Http\Middleware\HandleCors;
use Illuminate\Http\Middleware\TrustProxies;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
@ -28,11 +30,13 @@ class Kernel extends HttpKernel
* @var array<int,class-string>
*/
protected $middleware = [
CheckForMaintenanceMode::class,
TrustHosts::class,
TrustProxies::class,
HandleCors::class,
PreventRequestsDuringMaintenance::class,
ValidatePostSize::class,
TrimStrings::class,
ForceHttps::class,
TrustHosts::class,
];
/**

View file

@ -12,6 +12,7 @@ class TrustHosts extends IlluminateTrustHost
public function hosts(): array
{
return [
config('app.url'),
$this->allSubdomainsOfApplicationUrl(),
];
}

View file

@ -0,0 +1,16 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
* Setting this to '*' will trust all proxies, as we don't know the IP address of the proxy server.
*
* @var array<string>
*/
protected $proxies = ['*'];
}