From 0fe4a870874416507c5118dad9f835203ba2c588 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 16 Nov 2026 11:38:48 -0800 Subject: [PATCH] Harden default Pusher credentials for production Soketi use. Remove insecure broadcasting fallbacks, validate credentials at boot, and generate unique values on install when using the pusher driver. Co-authored-by: Cursor --- .env.example | 2 + .../ValidatesPusherCredentials.php | 59 ++++++++++++++ ProcessMaker/Console/Commands/Install.php | 24 ++++++ .../Providers/BroadcastServiceProvider.php | 3 + config/broadcasting.php | 6 +- .../ValidatesPusherCredentialsTest.php | 76 +++++++++++++++++++ 6 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 ProcessMaker/Broadcasting/ValidatesPusherCredentials.php create mode 100644 tests/unit/ProcessMaker/Broadcasting/ValidatesPusherCredentialsTest.php diff --git a/.env.example b/.env.example index c451173583..7c1ea33507 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,8 @@ LARAVEL_ECHO_SERVER_DEBUG=FALSE PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= +# Set to true only for local dev when using the legacy app-id/app-key/app-secret Soketi defaults +PUSHER_ALLOW_INSECURE_DEFAULTS=false PUSHER_CLUSTER= PUSHER_TLS=TRUE PUSHER_DEBUG=FALSE diff --git a/ProcessMaker/Broadcasting/ValidatesPusherCredentials.php b/ProcessMaker/Broadcasting/ValidatesPusherCredentials.php new file mode 100644 index 0000000000..2eb3712e15 --- /dev/null +++ b/ProcessMaker/Broadcasting/ValidatesPusherCredentials.php @@ -0,0 +1,59 @@ + + */ + private const INSECURE_VALUES = [ + self::INSECURE_APP_ID, + self::INSECURE_APP_KEY, + self::INSECURE_APP_SECRET, + '', + ]; + + public static function validate(): void + { + if (config('broadcasting.default') !== 'pusher') { + return; + } + + if (config('app.env') !== 'production') { + return; + } + + if (filter_var(env('PUSHER_ALLOW_INSECURE_DEFAULTS', false), FILTER_VALIDATE_BOOLEAN)) { + return; + } + + $connection = config('broadcasting.connections.pusher'); + + $credentials = [ + 'PUSHER_APP_ID' => $connection['app_id'] ?? null, + 'PUSHER_APP_KEY' => $connection['key'] ?? null, + 'PUSHER_APP_SECRET' => $connection['secret'] ?? null, + ]; + + foreach ($credentials as $name => $value) { + if ($value === null || in_array((string) $value, self::INSECURE_VALUES, true)) { + throw new RuntimeException( + "{$name} must be set to a unique value when BROADCAST_DRIVER=pusher in production. " + . 'Set PUSHER_ALLOW_INSECURE_DEFAULTS=true only for local development.' + ); + } + } + } +} diff --git a/ProcessMaker/Console/Commands/Install.php b/ProcessMaker/Console/Commands/Install.php index b9b6616ed7..0b1113ddc3 100644 --- a/ProcessMaker/Console/Commands/Install.php +++ b/ProcessMaker/Console/Commands/Install.php @@ -217,6 +217,8 @@ public function handle() // Set laravel echo server settings $this->env['LARAVEL_ECHO_SERVER_AUTH_HOST'] = $this->option('echo-host') ? $this->option('echo-host') : $this->env['APP_URL']; + $this->ensurePusherCredentials(); + // Set path and Docker settings Storage::disk('local')->makeDirectory('scripts'); $this->env['PROCESSMAKER_SCRIPTS_HOME'] = storage_path('app/scripts'); @@ -317,6 +319,28 @@ public function handle() return 0; } + /** + * Generate unique Pusher credentials when broadcasting uses the pusher driver. + */ + private function ensurePusherCredentials(): void + { + if (($this->env['BROADCAST_DRIVER'] ?? '') !== 'pusher') { + return; + } + + if (empty($this->env['PUSHER_APP_ID'])) { + $this->env['PUSHER_APP_ID'] = 'pm-' . Str::lower(Str::random(12)); + } + + if (empty($this->env['PUSHER_APP_KEY'])) { + $this->env['PUSHER_APP_KEY'] = Str::random(32); + } + + if (empty($this->env['PUSHER_APP_SECRET'])) { + $this->env['PUSHER_APP_SECRET'] = Str::random(64); + } + } + /** * Configure the username, email, password of the admin user */ diff --git a/ProcessMaker/Providers/BroadcastServiceProvider.php b/ProcessMaker/Providers/BroadcastServiceProvider.php index 17b5176608..7fd06a7452 100644 --- a/ProcessMaker/Providers/BroadcastServiceProvider.php +++ b/ProcessMaker/Providers/BroadcastServiceProvider.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactory; use Illuminate\Support\Facades\Broadcast; use Illuminate\Support\ServiceProvider; +use ProcessMaker\Broadcasting\ValidatesPusherCredentials; use ProcessMaker\Multitenancy\Broadcasting\TenantAwareBroadcastManager; class BroadcastServiceProvider extends ServiceProvider @@ -18,6 +19,8 @@ class BroadcastServiceProvider extends ServiceProvider */ public function boot() { + ValidatesPusherCredentials::validate(); + if (config('app.multitenancy')) { $this->useTenantAwareBroadcastManager(); } diff --git a/config/broadcasting.php b/config/broadcasting.php index d5a71197ce..6ffe86fe7f 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -43,9 +43,9 @@ 'pusher' => [ 'driver' => 'pusher', - 'key' => env('PUSHER_APP_KEY', 'app-key'), - 'secret' => env('PUSHER_APP_SECRET', 'app-secret'), - 'app_id' => env('PUSHER_APP_ID', 'app-id'), + 'key' => env('PUSHER_APP_KEY'), + 'secret' => env('PUSHER_APP_SECRET'), + 'app_id' => env('PUSHER_APP_ID'), 'options' => array_merge([ 'cluster' => env('PUSHER_CLUSTER', 'mt1'), 'debug' => env('PUSHER_DEBUG', false), diff --git a/tests/unit/ProcessMaker/Broadcasting/ValidatesPusherCredentialsTest.php b/tests/unit/ProcessMaker/Broadcasting/ValidatesPusherCredentialsTest.php new file mode 100644 index 0000000000..7dcf07be25 --- /dev/null +++ b/tests/unit/ProcessMaker/Broadcasting/ValidatesPusherCredentialsTest.php @@ -0,0 +1,76 @@ + 'log']); + + ValidatesPusherCredentials::validate(); + + $this->addToAssertionCount(1); + } + + public function testAllowsInsecureDefaultsInNonProduction(): void + { + config([ + 'app.env' => 'local', + 'broadcasting.default' => 'pusher', + 'broadcasting.connections.pusher' => [ + 'app_id' => ValidatesPusherCredentials::INSECURE_APP_ID, + 'key' => ValidatesPusherCredentials::INSECURE_APP_KEY, + 'secret' => ValidatesPusherCredentials::INSECURE_APP_SECRET, + ], + ]); + + ValidatesPusherCredentials::validate(); + + $this->addToAssertionCount(1); + } + + public function testRejectsInsecureDefaultsInProduction(): void + { + config([ + 'app.env' => 'production', + 'broadcasting.default' => 'pusher', + 'broadcasting.connections.pusher' => [ + 'app_id' => ValidatesPusherCredentials::INSECURE_APP_ID, + 'key' => ValidatesPusherCredentials::INSECURE_APP_KEY, + 'secret' => ValidatesPusherCredentials::INSECURE_APP_SECRET, + ], + ]); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('PUSHER_APP_ID'); + + ValidatesPusherCredentials::validate(); + } + + public function testAllowsInsecureDefaultsWhenExplicitlyEnabled(): void + { + config([ + 'app.env' => 'production', + 'broadcasting.default' => 'pusher', + 'broadcasting.connections.pusher' => [ + 'app_id' => ValidatesPusherCredentials::INSECURE_APP_ID, + 'key' => ValidatesPusherCredentials::INSECURE_APP_KEY, + 'secret' => ValidatesPusherCredentials::INSECURE_APP_SECRET, + ], + ]); + + putenv('PUSHER_ALLOW_INSECURE_DEFAULTS=true'); + + try { + ValidatesPusherCredentials::validate(); + $this->addToAssertionCount(1); + } finally { + putenv('PUSHER_ALLOW_INSECURE_DEFAULTS'); + } + } +}