From 19e704ccc30d021131335ae407af386952b82fe8 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Wed, 17 Jul 2024 00:07:58 +0200 Subject: [PATCH] feat: implement and use new confg key for trusted hosts (#1797) --- .env.example | 5 +++++ app/Http/Middleware/TrustHosts.php | 4 +--- config/app.php | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 7f089a41..d6036dec 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,11 @@ APP_ENV=production APP_DEBUG=true APP_URL=http://localhost:8000 +# A comma-separated list of (Koel server) hostnames accepted to access Koel. +# Leave this empty to allow access to Koel with any hostname. +# Example: localhost,192.168.0.1,yourdomain.com +TRUSTED_HOSTS= + # A random 32-char string. You can leave this empty if use php artisan koel:init. APP_KEY= diff --git a/app/Http/Middleware/TrustHosts.php b/app/Http/Middleware/TrustHosts.php index 85321dba..7b6ecf8b 100644 --- a/app/Http/Middleware/TrustHosts.php +++ b/app/Http/Middleware/TrustHosts.php @@ -11,8 +11,6 @@ class TrustHosts extends IlluminateTrustHost */ public function hosts(): array { - return [ - $this->allSubdomainsOfApplicationUrl(), - ]; + return config('app.trusted_hosts'); } } diff --git a/config/app.php b/config/app.php index a470b7f6..517918b3 100644 --- a/config/app.php +++ b/config/app.php @@ -32,6 +32,19 @@ return [ 'url' => env('APP_URL', 'http://localhost'), + /* + |-------------------------------------------------------------------------- + | Trusted hosts + |-------------------------------------------------------------------------- + | + | An array of (Koel server) hostnames accepted to access Koel. + | An empty array allows access to Koel with any hostname. + | Example: ['localhost', '192.168.0.1', 'yourdomain.com'] + | + */ + + 'trusted_hosts' => explode(',', env('TRUSTED_HOSTS', '')), + /* |-------------------------------------------------------------------------- | Application Timezone