From d2d60f6e8b7a5954e943700d6d7613629427fb63 Mon Sep 17 00:00:00 2001 From: TheMaddax Date: Wed, 17 Dec 2025 22:00:12 -0700 Subject: [PATCH] Add TrustProxies middleware to fix HTTPS detection behind Caddy --- app/Http/Middleware/TrustProxies.php | 28 ++++++++++++++++++++++++++++ bootstrap/app.php | 3 +++ 2 files changed, 31 insertions(+) create mode 100644 app/Http/Middleware/TrustProxies.php diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php new file mode 100644 index 00000000..559dd2fc --- /dev/null +++ b/app/Http/Middleware/TrustProxies.php @@ -0,0 +1,28 @@ +|string|null + */ + protected $proxies = '*'; + + /** + * The headers that should be used to detect proxies. + * + * @var int + */ + protected $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_AWS_ELB; +} diff --git a/bootstrap/app.php b/bootstrap/app.php index d0e01a00..c8917026 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -11,6 +11,9 @@ return Application::configure(basePath: dirname(__DIR__)) health: '/up', ) ->withMiddleware(function (Middleware $middleware): void { + // Trust proxies for HTTPS detection + $middleware->trustProxies(at: '*'); + $middleware->web(append: [ \App\Http\Middleware\HandleInertiaRequests::class, \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,