An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(traffic-analytics): stop leaking geoip key and gate sentinel restart
Aditya Tripathi7c01f63f53de
diff --git a/app/Actions/Server/ConfigureTrafficAnalytics.php b/app/Actions/Server/ConfigureTrafficAnalytics.phpindex 4da6e79dff..9121443c62 100644--- a/app/Actions/Server/ConfigureTrafficAnalytics.php+++ b/app/Actions/Server/ConfigureTrafficAnalytics.php@@ -13,6 +13,8 @@ class ConfigureTrafficAnalyticspublic function handle(Server $server, bool $enable): void{+ $sentinelWasEnabled = (bool) $server->settings->is_sentinel_enabled;+$server->settings->is_traffic_analytics_enabled = $enable;$server->settings->save();$server->refresh();@@ -21,7 +23,11 @@ class ConfigureTrafficAnalyticsGetProxyConfiguration::run($server, forceRegenerate: true);RestartProxyJob::dispatch($server);- // Recreate Sentinel with the traffic env + proxy-log mount (or without, when disabling).- StartSentinel::run($server, restart: true);+ // Recreate Sentinel so it picks up (enabling) or drops (disabling) the traffic env + proxy-log mount.+ // Enabling analytics needs Sentinel running; when disabling, only restart if Sentinel was already+ // enabled so we never turn Sentinel on as a side effect of disabling analytics.+ if ($enable || $sentinelWasEnabled) {+ StartSentinel::run($server, restart: true);+ }}}diff --git a/app/Actions/Server/StartSentinel.php b/app/Actions/Server/StartSentinel.phpindex 04c980c80b..9d0f16c293 100644--- a/app/Actions/Server/StartSentinel.php+++ b/app/Actions/Server/StartSentinel.php@@ -30,7 +30,7 @@ class StartSentinel'GEOIP_REFRESH_DAYS' => (string) ($settings->geoip_refresh_days ?: 30),];$license = data_get($settings, 'geoip_maxmind_license_key');- if (filled($license)) {+ if ($settings->is_geoip_enabled && filled($license)) {$env['GEOIP_MAXMIND_LICENSE_KEY'] = $license;}diff --git a/app/Livewire/Dashboard/TrafficAnalytics.php b/app/Livewire/Dashboard/TrafficAnalytics.phpindex 9de3f7fd16..b8b2ce3ed9 100644--- a/app/Livewire/Dashboard/TrafficAnalytics.php+++ b/app/Livewire/Dashboard/TrafficAnalytics.php@@ -86,9 +86,12 @@ class TrafficAnalytics extends Component}} catch (\Throwable $e) {// Leave this server out of the sparkline series.+ \Log::debug('Traffic series fetch failed', ['server' => $server->uuid, 'error' => $e->getMessage()]);}} catch (\Throwable $e) {// Skip unreachable/failed servers so one bad server doesn't break the whole summary.+ \Log::debug('Traffic overview fetch failed', ['server' => $server->uuid, 'error' => $e->getMessage()]);+continue;}}diff --git a/app/Services/SentinelTrafficClient.php b/app/Services/SentinelTrafficClient.phpindex e42caa1f99..b7722d03bd 100644--- a/app/Services/SentinelTrafficClient.php+++ b/app/Services/SentinelTrafficClient.php@@ -170,9 +170,15 @@ class SentinelTrafficClientprivate function guard(string $response): string{- if (str($response)->contains('"error"')) {- $error = data_get(json_decode($response, true), 'error', 'Traffic analytics request failed.');- throw new \Exception($error);+ $payload = json_decode($response, true);++ if (! is_array($payload)) {+ throw new \RuntimeException('Traffic analytics returned an invalid response.');+ }++ if (array_key_exists('error', $payload)) {+ $error = data_get($payload, 'error');+ throw new \RuntimeException(is_string($error) ? $error : 'Traffic analytics request failed.');}return $response;diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex d9444ec596..e82bb9b6df 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -4894,8 +4894,13 @@ function refererHost(?string $referer): ?string}/**- * Favicon URL for a host, served by DuckDuckGo's icon proxy (no API key, no- * hotlink-referrer leakage). Used to decorate referrer rows in analytics.+ * Favicon URL for a host, served by DuckDuckGo's icon proxy. Used to decorate+ * referrer rows in analytics.+ *+ * Note: rendering these icons makes the operator's browser request each favicon+ * from icons.duckduckgo.com, which discloses the referrer hostnames of the+ * operator's own traffic to that third party. Same applies to countryFlagUrl()+ * (flagcdn.com). No API key is required.*/function refererFaviconUrl(string $host): string{@@ -5187,6 +5192,7 @@ function countryName(?string $a2): string'VU' => 'Vanuatu','WF' => 'Wallis & Futuna','WS' => 'Samoa',+ 'XK' => 'Kosovo','YE' => 'Yemen','YT' => 'Mayotte','ZA' => 'South Africa',diff --git a/resources/views/livewire/server/sentinel.blade.php b/resources/views/livewire/server/sentinel.blade.phpindex 6ed58377f6..0cf5b2f74d 100644--- a/resources/views/livewire/server/sentinel.blade.php+++ b/resources/views/livewire/server/sentinel.blade.php@@ -115,7 +115,8 @@<x-forms.input canGate="update" :canResource="$server" type="number" min="1"id="trafficRetention1dDays" label="Daily retention" requiredhelper="Days of daily rollups to keep before deletion." />- <x-forms.listbox id="isGeoipEnabled" label="Geolocation"+ <x-forms.listbox canGate="update" :canResource="$server"+ id="isGeoipEnabled" label="Geolocation":options="[['value' => true, 'label' => 'Enabled'],['value' => false, 'label' => 'Disabled'],diff --git a/resources/views/livewire/traffic/_breakdown-section.blade.php b/resources/views/livewire/traffic/_breakdown-section.blade.phpindex c955350ba3..a6d864425a 100644--- a/resources/views/livewire/traffic/_breakdown-section.blade.php+++ b/resources/views/livewire/traffic/_breakdown-section.blade.php@@ -16,7 +16,7 @@$maxRequests = max(1, (int) collect($rows)->max('requests'));@endphp<x-application.settings-section id="analytics-{{ $dimension }}-section" :title="$label" :helper="$helper" flush>- @if (empty($rows))+ @if (collect($rows)->isEmpty())<x-empty size="sm" title="No data"description="No {{ strtolower($label) }} data for the selected range." icon-name="network" />@else@@ -36,7 +36,7 @@$requests = (int) ($row['requests'] ?? 0);$width = min(100, round(($requests / $maxRequests) * 100, 1));@endphp- <div wire:key="analytics-{{ $dimension }}-{{ $loop->index }}"+ <div wire:key="analytics-{{ $dimension }}-{{ md5($value) }}"x-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"class="flex min-h-11 items-center gap-3 border-b border-neutral-200 px-4 py-2 last:border-b-0 dark:border-white/[0.07]">@if ($dimension === 'referer' && $host)diff --git a/resources/views/livewire/traffic/_live-toggle.blade.php b/resources/views/livewire/traffic/_live-toggle.blade.phpindex 3169807e7b..3cb76976eb 100644--- a/resources/views/livewire/traffic/_live-toggle.blade.php+++ b/resources/views/livewire/traffic/_live-toggle.blade.php@@ -9,7 +9,9 @@@if ($range === '24h')<div x-data="{ live: $wire.entangle('live').live }"x-init="- if (localStorage.getItem('traffic-live') === '0') { live = false; }+ const stored = localStorage.getItem('traffic-live');+ if (stored === '0') { live = false; }+ if (stored === '1') { live = true; }$watch('live', value => localStorage.setItem('traffic-live', value ? '1' : '0'));"><button type="button"diff --git a/resources/views/livewire/traffic/_paths-list.blade.php b/resources/views/livewire/traffic/_paths-list.blade.phpindex c889e363e0..be841a5bff 100644--- a/resources/views/livewire/traffic/_paths-list.blade.php+++ b/resources/views/livewire/traffic/_paths-list.blade.php@@ -13,7 +13,7 @@$keyPrefix = $keyPrefix ?? 'analytics-path';$maxRequests = max(1, (int) collect($paths)->max('requests'));@endphp-@if (empty($paths))+@if (collect($paths)->isEmpty())<x-empty size="sm" title="No path data" description="No requests were recorded for the selected range."icon-name="unordered-list" />@else@@ -26,7 +26,7 @@$requests = (int) ($path['requests'] ?? 0);$width = min(100, round(($requests / $maxRequests) * 100, 1));@endphp- <div wire:key="{{ $keyPrefix }}-{{ $loop->index }}"+ <div wire:key="{{ $keyPrefix }}-{{ md5($pathStr) }}"x-show="{{ $loop->index }} >= page * per && {{ $loop->index }} < (page + 1) * per"class="flex min-h-11 items-center gap-3 border-b border-neutral-200 px-4 py-2 last:border-b-0 dark:border-white/[0.07]">@if ($href)diff --git a/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.php b/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.phpindex 8952973601..547fbcee38 100644--- a/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.php+++ b/tests/Feature/TrafficAnalytics/ApplicationAnalyticsTest.php@@ -84,17 +84,7 @@ beforeEach(function () {$this->actingAs($this->user);session(['currentTeam' => $this->team]);- $this->privateKey = PrivateKey::create([- 'name' => 'Test Key',- 'private_key' => '-----BEGIN OPENSSH PRIVATE KEY------b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW-QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk-hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA-AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV-uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==------END OPENSSH PRIVATE KEY-----',- 'team_id' => $this->team->id,- ]);+ $this->privateKey = PrivateKey::factory()->create(['team_id' => $this->team->id]);$this->project = Project::factory()->create(['team_id' => $this->team->id]);$this->environment = Environment::factory()->create(['project_id' => $this->project->id]);diff --git a/tests/Feature/TrafficAnalytics/CaddyProxyVolumeTest.php b/tests/Feature/TrafficAnalytics/CaddyProxyVolumeTest.phpindex be99d63702..8ae029cb63 100644--- a/tests/Feature/TrafficAnalytics/CaddyProxyVolumeTest.php+++ b/tests/Feature/TrafficAnalytics/CaddyProxyVolumeTest.php@@ -18,17 +18,7 @@ beforeEach(function () {$user = User::factory()->create();$this->team = $user->teams()->first();- $this->privateKey = PrivateKey::create([- 'name' => 'Test Key',- 'private_key' => '-----BEGIN OPENSSH PRIVATE KEY------b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW-QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk-hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA-AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV-uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==------END OPENSSH PRIVATE KEY-----',- 'team_id' => $this->team->id,- ]);+ $this->privateKey = PrivateKey::factory()->create(['team_id' => $this->team->id]);});it('does not mount the traffic volume for caddy when traffic analytics is disabled', function () {diff --git a/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php b/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.phpindex e0f6bff9a4..3469db4b85 100644--- a/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php+++ b/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php@@ -64,17 +64,7 @@ beforeEach(function () {$this->actingAs($this->user);session(['currentTeam' => $this->team]);- $this->privateKey = PrivateKey::create([- 'name' => 'Test Key',- 'private_key' => '-----BEGIN OPENSSH PRIVATE KEY------b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW-QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk-hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA-AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV-uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==------END OPENSSH PRIVATE KEY-----',- 'team_id' => $this->team->id,- ]);+ $this->privateKey = PrivateKey::factory()->create(['team_id' => $this->team->id]);});it('renders the team traffic summary aggregated across servers with an approximate badge', function () {diff --git a/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php b/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.phpindex ac24331d52..4e06079a6c 100644--- a/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php+++ b/tests/Feature/TrafficAnalytics/StartSentinelTrafficTest.php@@ -49,6 +49,8 @@ it('passes custom traffic settings as sentinel env', function () {$server->settings->traffic_retention_1d_days = 180;$server->settings->is_geoip_enabled = false;$server->settings->geoip_refresh_days = 7;+ // A key may still be stored while GeoIP is off; it must not reach Sentinel.+ $server->settings->geoip_maxmind_license_key = 'secret-maxmind-key';$server->settings->save();$env = StartSentinel::sentinelTrafficEnvironment($server->fresh());@@ -60,3 +62,14 @@ it('passes custom traffic settings as sentinel env', function () {expect($env['GEOIP_REFRESH_DAYS'])->toBe('7');expect($env)->not->toHaveKey('GEOIP_MAXMIND_LICENSE_KEY');});++it('injects the maxmind license key only when geoip is enabled', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $server->settings->is_traffic_analytics_enabled = true;+ $server->settings->is_geoip_enabled = true;+ $server->settings->geoip_maxmind_license_key = 'secret-maxmind-key';+ $server->settings->save();++ $env = StartSentinel::sentinelTrafficEnvironment($server->fresh());+ expect($env['GEOIP_MAXMIND_LICENSE_KEY'])->toBe('secret-maxmind-key');+});diff --git a/tests/Feature/TrafficAnalytics/TraefikLogrotateSidecarTest.php b/tests/Feature/TrafficAnalytics/TraefikLogrotateSidecarTest.phpindex 80892a5bb7..e629a284bc 100644--- a/tests/Feature/TrafficAnalytics/TraefikLogrotateSidecarTest.php+++ b/tests/Feature/TrafficAnalytics/TraefikLogrotateSidecarTest.php@@ -18,17 +18,7 @@ beforeEach(function () {$user = User::factory()->create();$this->team = $user->teams()->first();- $this->privateKey = PrivateKey::create([- 'name' => 'Test Key',- 'private_key' => '-----BEGIN OPENSSH PRIVATE KEY------b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW-QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk-hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA-AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV-uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==------END OPENSSH PRIVATE KEY-----',- 'team_id' => $this->team->id,- ]);+ $this->privateKey = PrivateKey::factory()->create(['team_id' => $this->team->id]);});it('does not add a traefik-logrotate sidecar when traffic analytics is disabled', function () {