From 6e8714aec516f365c8e7fce021c3fbb14a1a84b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Carodej?= Date: Fri, 22 Apr 2022 09:44:40 +0200 Subject: [PATCH] websocket allowed origins implementation --- .env.example | 1 + config/websockets.php | 3 +- .../Commands/SetupWebsocketEnvironment.php | 48 +++++++++++++++++++ src/App/Console/Kernel.php | 2 + 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/App/Console/Commands/SetupWebsocketEnvironment.php diff --git a/.env.example b/.env.example index 74d93ee7..98a73e3b 100644 --- a/.env.example +++ b/.env.example @@ -90,6 +90,7 @@ PUSHER_APP_CLUSTER=mt1 PUSHER_APP_HOST= PUSHER_APP_PORT= PUSHER_APP_TLS=true +PUSHER_APP_ALLOWED_ORIGIN= IS_ADMIN_VUEFILEMANAGER_BAR=true IS_SETUP_WIZARD_DEMO=false diff --git a/config/websockets.php b/config/websockets.php index f9eec65c..27f0986e 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -46,8 +46,7 @@ return [ * This array contains the hosts of which you want to allow incoming requests. * Leave this empty if you want to accept requests from all hosts. */ - 'allowed_origins' => [ - ], + 'allowed_origins' => explode(',', env('PUSHER_APP_ALLOWED_ORIGIN', '')), /* * The maximum request size in kilobytes that is allowed for an incoming WebSocket request. diff --git a/src/App/Console/Commands/SetupWebsocketEnvironment.php b/src/App/Console/Commands/SetupWebsocketEnvironment.php new file mode 100644 index 00000000..48f3f8c3 --- /dev/null +++ b/src/App/Console/Commands/SetupWebsocketEnvironment.php @@ -0,0 +1,48 @@ +ask('Type host of which you want to allow incoming requests. If you want to accept multiple hosts, separate them with comma(,)'); + + // Store origins to the .env file + setEnvironmentValue([ + 'PUSHER_APP_ALLOWED_ORIGIN' => $origins, + 'APP_ENV' => 'production', + 'APP_DEBUG' => 'false', + ]); + + $this->info('Your host/s was stored successfully.'); + + // Generate new app key + $this->call('key:generate', [ + '--force' => true, + ]); + + // Clear cache + $this->call('config:clear'); + + $this->info('Everything is done, congratulations! 🥳🥳🥳'); + } +} diff --git a/src/App/Console/Kernel.php b/src/App/Console/Kernel.php index 048e47f9..8a44a3b7 100644 --- a/src/App/Console/Kernel.php +++ b/src/App/Console/Kernel.php @@ -1,6 +1,7 @@