From c3c1f703e8584bdd5274838b7ac251a26608c66b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 04:46:11 +0000 Subject: [PATCH 1/6] fix(install): omit admin PII from self-hosted telemetry ping Stop sending administrator name/email in the one-time growth analytics payload and honor DO_NOT_TRACK / _APP_TELEMETRY=disabled opt-out. Fixes #12863 Co-authored-by: Chirag Aggarwal --- app/config/variables.php | 9 ++ src/Appwrite/Platform/Tasks/Install.php | 120 ++++++++++++++-------- tests/unit/Platform/Tasks/InstallTest.php | 118 +++++++++++++++++++++ 3 files changed, 204 insertions(+), 43 deletions(-) create mode 100644 tests/unit/Platform/Tasks/InstallTest.php diff --git a/app/config/variables.php b/app/config/variables.php index 789890ae55..6c2ef0f389 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -43,6 +43,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_TELEMETRY', + 'description' => 'Controls the one-time anonymous install/upgrade ping the self-hosted setup sends to Appwrite. By default, set to \'enabled\'. To opt out, set to \'disabled\' (the cross-vendor \'DO_NOT_TRACK\' standard is honored as well). The ping is anonymous and never includes the administrator\'s name or email.', + 'introduction' => '', + 'default' => 'enabled', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_LOCKING_ENABLED', 'description' => 'Enable distributed locking for platform writes. Locks coordinate concurrent updates across API pods so read-modify-write operations on shared documents do not lose updates. By default, set to \'enabled\'. Set to \'disabled\' as an emergency kill switch; locks become no-ops and concurrent writes will race.', diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index ac5b2c1a03..f32c5a8e19 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -15,6 +15,7 @@ use Utopia\Config\Config; use Utopia\Console; use Utopia\Fetch\Client; use Utopia\Platform\Action; +use Utopia\System\System; use Utopia\Validator\Boolean; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; @@ -691,11 +692,11 @@ class Install extends Action // Run tracking in a coroutine when inside a Swoole // request so it doesn't block the worker. if (Coroutine::getCid() !== -1) { - go(function () use ($input, $isUpgrade, $version, $account) { - $this->trackSelfHostedInstall($input, $isUpgrade, $version, $account); + go(function () use ($input, $isUpgrade, $version) { + $this->trackSelfHostedInstall($input, $isUpgrade, $version); }); } else { - $this->trackSelfHostedInstall($input, $isUpgrade, $version, $account); + $this->trackSelfHostedInstall($input, $isUpgrade, $version); } if ($isCLI) { @@ -845,55 +846,18 @@ class Install extends Action ); } - private function trackSelfHostedInstall(array $input, bool $isUpgrade, string $version, array $account): void + private function trackSelfHostedInstall(array $input, bool $isUpgrade, string $version): void { if ($this->isLocalInstall()) { return; } - $appEnv = $input['_APP_ENV'] ?? 'development'; - $domain = $input['_APP_DOMAIN'] ?? 'localhost'; + $payload = $this->buildSelfHostedInstallPayload($input, $isUpgrade, $version); - /* local or test instance */ - if ($appEnv !== 'production') { + if ($payload === null) { return; } - /* prod but local or test instance */ - if ($domain === 'localhost' - || str_starts_with($domain, '127.') - || str_starts_with($domain, '0.0.0.0') - ) { - return; - } - - $type = $isUpgrade ? 'upgrade' : 'install'; - $database = $input['_APP_DB_ADAPTER'] ?? 'postgresql'; - $name = $account['name'] ?? 'Admin'; - $email = $account['email'] ?? 'admin@selfhosted.local'; - - $hostIp = @gethostbyname($domain); - - $payload = [ - 'action' => $type, - 'account' => 'self-hosted', - 'url' => 'https://' . $domain, - 'category' => 'self_hosted', - 'label' => 'self_hosted_' . $type, - 'version' => $version, - 'data' => json_encode([ - 'name' => $name, - 'email' => $email, - 'domain' => $domain, - 'database' => $database, - 'ip' => ($hostIp !== $domain) ? $hostIp : null, - 'os' => php_uname('s') . ' ' . php_uname('r'), - 'arch' => php_uname('m'), - 'cpus' => ((int) trim((string) \shell_exec('nproc'))) ?: null, - 'ram' => (int) round(((float) trim((string) \shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\''))) / 1024), - ]), - ]; - try { $client = new Client(); $client @@ -906,6 +870,76 @@ class Install extends Action } } + /** + * Build the anonymous self-hosted install/upgrade analytics payload. + * + * Returns null when tracking must not happen (opt-out or non-production). + * The payload never includes the administrator's name or email (#12863). + * + * @param array $input Resolved environment variables + * @return array|null + */ + public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version): ?array + { + if ($this->isTelemetryDisabled()) { + return null; + } + + $appEnv = $input['_APP_ENV'] ?? 'development'; + $domain = $input['_APP_DOMAIN'] ?? 'localhost'; + + /* local or test instance */ + if ($appEnv !== 'production') { + return null; + } + + /* prod but local or test instance */ + if ($domain === 'localhost' + || str_starts_with($domain, '127.') + || str_starts_with($domain, '0.0.0.0') + ) { + return null; + } + + $type = $isUpgrade ? 'upgrade' : 'install'; + $database = $input['_APP_DB_ADAPTER'] ?? 'postgresql'; + + $hostIp = @gethostbyname($domain); + + return [ + 'action' => $type, + 'account' => 'self-hosted', + 'url' => 'https://' . $domain, + 'category' => 'self_hosted', + 'label' => 'self_hosted_' . $type, + 'version' => $version, + 'data' => json_encode([ + 'domain' => $domain, + 'database' => $database, + 'ip' => ($hostIp !== $domain) ? $hostIp : null, + 'os' => php_uname('s') . ' ' . php_uname('r'), + 'arch' => php_uname('m'), + 'cpus' => ((int) trim((string) \shell_exec('nproc'))) ?: null, + 'ram' => (int) round(((float) trim((string) \shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\''))) / 1024), + ]), + ]; + } + + /** + * Whether the operator opted out of anonymous install/upgrade telemetry. + * + * Honors DO_NOT_TRACK (https://consoledonottrack.com) and _APP_TELEMETRY=disabled. + */ + public function isTelemetryDisabled(): bool + { + $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); + if ($doNotTrack === '1' || $doNotTrack === 'true') { + return true; + } + + return \strtolower((string) System::getEnv('_APP_TELEMETRY', '')) === 'disabled'; + } + /** * Wait for the Appwrite API to respond. Builds candidate URLs based on * the runtime context and returns whichever responds first. diff --git a/tests/unit/Platform/Tasks/InstallTest.php b/tests/unit/Platform/Tasks/InstallTest.php new file mode 100644 index 0000000000..a5573f0453 --- /dev/null +++ b/tests/unit/Platform/Tasks/InstallTest.php @@ -0,0 +1,118 @@ +install = new Install(); + } + + protected function tearDown(): void + { + \putenv('DO_NOT_TRACK'); + \putenv('_APP_TELEMETRY'); + } + + /** + * @return array + */ + private function productionInput(): array + { + return [ + '_APP_ENV' => 'production', + '_APP_DOMAIN' => 'example.com', + '_APP_DB_ADAPTER' => 'mariadb', + ]; + } + + public function testPayloadIsAnonymousAndOmitsAdminNameAndEmail(): void + { + $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6'); + + $this->assertIsArray($payload); + $this->assertSame('install', $payload['action']); + $this->assertSame('self-hosted', $payload['account']); + $this->assertSame('1.9.6', $payload['version']); + + $data = \json_decode($payload['data'], true); + $this->assertIsArray($data); + + // The whole point of #12863: no administrator PII in the ping. + $this->assertArrayNotHasKey('name', $data); + $this->assertArrayNotHasKey('email', $data); + + // Anonymous host/instance fields are still reported. + $this->assertSame('example.com', $data['domain']); + $this->assertSame('mariadb', $data['database']); + $this->assertArrayHasKey('os', $data); + $this->assertArrayHasKey('arch', $data); + } + + public function testUpgradeActionIsReported(): void + { + $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), true, '1.9.6'); + + $this->assertIsArray($payload); + $this->assertSame('upgrade', $payload['action']); + $this->assertSame('self_hosted_upgrade', $payload['label']); + } + + public function testDoNotTrackDisablesTelemetry(): void + { + \putenv('DO_NOT_TRACK=1'); + + $this->assertTrue($this->install->isTelemetryDisabled()); + $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); + } + + public function testDoNotTrackTrueValueDisablesTelemetry(): void + { + \putenv('DO_NOT_TRACK=true'); + + $this->assertTrue($this->install->isTelemetryDisabled()); + } + + public function testAppTelemetryDisabledDisablesTelemetry(): void + { + \putenv('_APP_TELEMETRY=disabled'); + + $this->assertTrue($this->install->isTelemetryDisabled()); + $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); + } + + public function testTelemetryEnabledByDefault(): void + { + $this->assertFalse($this->install->isTelemetryDisabled()); + } + + public function testNonProductionEnvironmentIsNotTracked(): void + { + $input = $this->productionInput(); + $input['_APP_ENV'] = 'development'; + + $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + } + + public function testLocalhostDomainIsNotTracked(): void + { + $input = $this->productionInput(); + $input['_APP_DOMAIN'] = 'localhost'; + + $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + } +} From 14acd9e3c2444d5ff569a20f45752b23c2a31363 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 04:52:10 +0000 Subject: [PATCH 2/6] fix(install): honor resolved telemetry opt-out and DO_NOT_TRACK=yes Check _APP_TELEMETRY from resolved installer input (existing .env) and accept the standard DO_NOT_TRACK=yes value so upgrade pings respect opt-out. Co-authored-by: Chirag Aggarwal --- src/Appwrite/Platform/Tasks/Install.php | 25 ++++++++++++++++++----- tests/unit/Platform/Tasks/InstallTest.php | 17 +++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index f32c5a8e19..280f48deef 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -881,7 +881,7 @@ class Install extends Action */ public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version): ?array { - if ($this->isTelemetryDisabled()) { + if ($this->isTelemetryDisabled($input)) { return null; } @@ -928,16 +928,31 @@ class Install extends Action /** * Whether the operator opted out of anonymous install/upgrade telemetry. * - * Honors DO_NOT_TRACK (https://consoledonottrack.com) and _APP_TELEMETRY=disabled. + * Honors DO_NOT_TRACK (https://consoledonottrack.com) and _APP_TELEMETRY=disabled + * from the process environment or resolved installer `$input` (e.g. existing `.env`). + * + * @param array|null $input Resolved environment variables */ - public function isTelemetryDisabled(): bool + public function isTelemetryDisabled(?array $input = null): bool { $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); - if ($doNotTrack === '1' || $doNotTrack === 'true') { + if (\in_array($doNotTrack, ['1', 'true', 'yes'], true)) { return true; } - return \strtolower((string) System::getEnv('_APP_TELEMETRY', '')) === 'disabled'; + $telemetry = \strtolower((string) System::getEnv('_APP_TELEMETRY', '')); + if ($telemetry === 'disabled') { + return true; + } + + if ($input !== null) { + $fromInput = \strtolower((string) ($input['_APP_TELEMETRY'] ?? '')); + if ($fromInput === 'disabled') { + return true; + } + } + + return false; } /** diff --git a/tests/unit/Platform/Tasks/InstallTest.php b/tests/unit/Platform/Tasks/InstallTest.php index a5573f0453..291a2abb66 100644 --- a/tests/unit/Platform/Tasks/InstallTest.php +++ b/tests/unit/Platform/Tasks/InstallTest.php @@ -87,6 +87,14 @@ final class InstallTest extends TestCase $this->assertTrue($this->install->isTelemetryDisabled()); } + public function testDoNotTrackYesValueDisablesTelemetry(): void + { + \putenv('DO_NOT_TRACK=yes'); + + $this->assertTrue($this->install->isTelemetryDisabled()); + $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); + } + public function testAppTelemetryDisabledDisablesTelemetry(): void { \putenv('_APP_TELEMETRY=disabled'); @@ -95,6 +103,15 @@ final class InstallTest extends TestCase $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); } + public function testResolvedInputTelemetryDisabledDisablesTelemetry(): void + { + $input = $this->productionInput(); + $input['_APP_TELEMETRY'] = 'disabled'; + + $this->assertTrue($this->install->isTelemetryDisabled($input)); + $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + } + public function testTelemetryEnabledByDefault(): void { $this->assertFalse($this->install->isTelemetryDisabled()); From 39137b3f2ca092a20f960f2db5a1bfc1e9770179 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 05:00:48 +0000 Subject: [PATCH 3/6] chore: retrigger CI after flaky Databases testTimeout Unrelated E2E timeout in DocumentsDBCustomServerTest::testTimeout. Co-authored-by: Chirag Aggarwal From 5b3651a142eb908d56288342f5fb8d6051d25757 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 05:09:28 +0000 Subject: [PATCH 4/6] chore: retrigger CI for flaky Databases testTimeout (2) Co-authored-by: Chirag Aggarwal From 1cd4b89d3b9e71abf2487ae118ac4b944f26c5a7 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 29 Jul 2026 16:35:19 +0530 Subject: [PATCH 5/6] fix(install): restore admin fields and opt out via DO_NOT_TRACK only Drop _APP_TELEMETRY in favor of the DO_NOT_TRACK standard (https://donottrack.sh/) and keep name/email in the install ping payload. Co-authored-by: Cursor --- app/config/variables.php | 9 ---- src/Appwrite/Platform/Tasks/Install.php | 48 ++++++++------------- tests/unit/Platform/Tasks/InstallTest.php | 51 +++++++++-------------- 3 files changed, 37 insertions(+), 71 deletions(-) diff --git a/app/config/variables.php b/app/config/variables.php index 6c2ef0f389..789890ae55 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -43,15 +43,6 @@ return [ 'question' => '', 'filter' => '' ], - [ - 'name' => '_APP_TELEMETRY', - 'description' => 'Controls the one-time anonymous install/upgrade ping the self-hosted setup sends to Appwrite. By default, set to \'enabled\'. To opt out, set to \'disabled\' (the cross-vendor \'DO_NOT_TRACK\' standard is honored as well). The ping is anonymous and never includes the administrator\'s name or email.', - 'introduction' => '', - 'default' => 'enabled', - 'required' => false, - 'question' => '', - 'filter' => '' - ], [ 'name' => '_APP_LOCKING_ENABLED', 'description' => 'Enable distributed locking for platform writes. Locks coordinate concurrent updates across API pods so read-modify-write operations on shared documents do not lose updates. By default, set to \'enabled\'. Set to \'disabled\' as an emergency kill switch; locks become no-ops and concurrent writes will race.', diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index 280f48deef..ee5a2af418 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -692,11 +692,11 @@ class Install extends Action // Run tracking in a coroutine when inside a Swoole // request so it doesn't block the worker. if (Coroutine::getCid() !== -1) { - go(function () use ($input, $isUpgrade, $version) { - $this->trackSelfHostedInstall($input, $isUpgrade, $version); + go(function () use ($input, $isUpgrade, $version, $account) { + $this->trackSelfHostedInstall($input, $isUpgrade, $version, $account); }); } else { - $this->trackSelfHostedInstall($input, $isUpgrade, $version); + $this->trackSelfHostedInstall($input, $isUpgrade, $version, $account); } if ($isCLI) { @@ -846,13 +846,13 @@ class Install extends Action ); } - private function trackSelfHostedInstall(array $input, bool $isUpgrade, string $version): void + private function trackSelfHostedInstall(array $input, bool $isUpgrade, string $version, array $account): void { if ($this->isLocalInstall()) { return; } - $payload = $this->buildSelfHostedInstallPayload($input, $isUpgrade, $version); + $payload = $this->buildSelfHostedInstallPayload($input, $isUpgrade, $version, $account); if ($payload === null) { return; @@ -871,17 +871,17 @@ class Install extends Action } /** - * Build the anonymous self-hosted install/upgrade analytics payload. + * Build the self-hosted install/upgrade analytics payload. * * Returns null when tracking must not happen (opt-out or non-production). - * The payload never includes the administrator's name or email (#12863). * * @param array $input Resolved environment variables + * @param array $account Administrator account details * @return array|null */ - public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version): ?array + public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version, array $account = []): ?array { - if ($this->isTelemetryDisabled($input)) { + if ($this->isTelemetryDisabled()) { return null; } @@ -903,6 +903,8 @@ class Install extends Action $type = $isUpgrade ? 'upgrade' : 'install'; $database = $input['_APP_DB_ADAPTER'] ?? 'postgresql'; + $name = $account['name'] ?? 'Admin'; + $email = $account['email'] ?? 'admin@selfhosted.local'; $hostIp = @gethostbyname($domain); @@ -914,6 +916,8 @@ class Install extends Action 'label' => 'self_hosted_' . $type, 'version' => $version, 'data' => json_encode([ + 'name' => $name, + 'email' => $email, 'domain' => $domain, 'database' => $database, 'ip' => ($hostIp !== $domain) ? $hostIp : null, @@ -926,33 +930,15 @@ class Install extends Action } /** - * Whether the operator opted out of anonymous install/upgrade telemetry. + * Whether the operator opted out of install/upgrade telemetry. * - * Honors DO_NOT_TRACK (https://consoledonottrack.com) and _APP_TELEMETRY=disabled - * from the process environment or resolved installer `$input` (e.g. existing `.env`). - * - * @param array|null $input Resolved environment variables + * Honors DO_NOT_TRACK (https://donottrack.sh/). */ - public function isTelemetryDisabled(?array $input = null): bool + public function isTelemetryDisabled(): bool { $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); - if (\in_array($doNotTrack, ['1', 'true', 'yes'], true)) { - return true; - } - $telemetry = \strtolower((string) System::getEnv('_APP_TELEMETRY', '')); - if ($telemetry === 'disabled') { - return true; - } - - if ($input !== null) { - $fromInput = \strtolower((string) ($input['_APP_TELEMETRY'] ?? '')); - if ($fromInput === 'disabled') { - return true; - } - } - - return false; + return \in_array($doNotTrack, ['1', 'true', 'yes'], true); } /** diff --git a/tests/unit/Platform/Tasks/InstallTest.php b/tests/unit/Platform/Tasks/InstallTest.php index 291a2abb66..cb27fa349e 100644 --- a/tests/unit/Platform/Tasks/InstallTest.php +++ b/tests/unit/Platform/Tasks/InstallTest.php @@ -17,7 +17,6 @@ final class InstallTest extends TestCase { // Ensure a deterministic, opted-in environment for each test. \putenv('DO_NOT_TRACK'); - \putenv('_APP_TELEMETRY'); $this->install = new Install(); } @@ -25,7 +24,6 @@ final class InstallTest extends TestCase protected function tearDown(): void { \putenv('DO_NOT_TRACK'); - \putenv('_APP_TELEMETRY'); } /** @@ -40,9 +38,20 @@ final class InstallTest extends TestCase ]; } - public function testPayloadIsAnonymousAndOmitsAdminNameAndEmail(): void + /** + * @return array + */ + private function account(): array { - $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6'); + return [ + 'name' => 'Jane Admin', + 'email' => 'jane@example.com', + ]; + } + + public function testPayloadIncludesAdminNameAndEmail(): void + { + $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account()); $this->assertIsArray($payload); $this->assertSame('install', $payload['action']); @@ -52,11 +61,8 @@ final class InstallTest extends TestCase $data = \json_decode($payload['data'], true); $this->assertIsArray($data); - // The whole point of #12863: no administrator PII in the ping. - $this->assertArrayNotHasKey('name', $data); - $this->assertArrayNotHasKey('email', $data); - - // Anonymous host/instance fields are still reported. + $this->assertSame('Jane Admin', $data['name']); + $this->assertSame('jane@example.com', $data['email']); $this->assertSame('example.com', $data['domain']); $this->assertSame('mariadb', $data['database']); $this->assertArrayHasKey('os', $data); @@ -65,7 +71,7 @@ final class InstallTest extends TestCase public function testUpgradeActionIsReported(): void { - $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), true, '1.9.6'); + $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), true, '1.9.6', $this->account()); $this->assertIsArray($payload); $this->assertSame('upgrade', $payload['action']); @@ -77,7 +83,7 @@ final class InstallTest extends TestCase \putenv('DO_NOT_TRACK=1'); $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); + $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account())); } public function testDoNotTrackTrueValueDisablesTelemetry(): void @@ -92,24 +98,7 @@ final class InstallTest extends TestCase \putenv('DO_NOT_TRACK=yes'); $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); - } - - public function testAppTelemetryDisabledDisablesTelemetry(): void - { - \putenv('_APP_TELEMETRY=disabled'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6')); - } - - public function testResolvedInputTelemetryDisabledDisablesTelemetry(): void - { - $input = $this->productionInput(); - $input['_APP_TELEMETRY'] = 'disabled'; - - $this->assertTrue($this->install->isTelemetryDisabled($input)); - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account())); } public function testTelemetryEnabledByDefault(): void @@ -122,7 +111,7 @@ final class InstallTest extends TestCase $input = $this->productionInput(); $input['_APP_ENV'] = 'development'; - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6', $this->account())); } public function testLocalhostDomainIsNotTracked(): void @@ -130,6 +119,6 @@ final class InstallTest extends TestCase $input = $this->productionInput(); $input['_APP_DOMAIN'] = 'localhost'; - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6')); + $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6', $this->account())); } } From dede2ab442f2c10e2761edad1040be769df41a8f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 29 Jul 2026 16:38:41 +0530 Subject: [PATCH 6/6] fix(install): honor DO_NOT_TRACK for self-hosted install telemetry Skip the install/upgrade analytics ping when DO_NOT_TRACK is set. Co-authored-by: Cursor --- src/Appwrite/Platform/Tasks/Install.php | 60 +++-------- tests/unit/Platform/Tasks/InstallTest.php | 124 ---------------------- 2 files changed, 16 insertions(+), 168 deletions(-) delete mode 100644 tests/unit/Platform/Tasks/InstallTest.php diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index ee5a2af418..7bbdf87350 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -852,45 +852,18 @@ class Install extends Action return; } - $payload = $this->buildSelfHostedInstallPayload($input, $isUpgrade, $version, $account); - - if ($payload === null) { + // Opt out via DO_NOT_TRACK (https://donottrack.sh/) + $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); + if (\in_array($doNotTrack, ['1', 'true', 'yes'], true)) { return; } - try { - $client = new Client(); - $client - ->setConnectTimeout(5000) - ->setTimeout(5000) - ->addHeader('Content-Type', 'application/json') - ->fetch(self::GROWTH_API_URL . '/analytics', Client::METHOD_POST, $payload); - } catch (\Throwable) { - // tracking shouldn't block installation - } - } - - /** - * Build the self-hosted install/upgrade analytics payload. - * - * Returns null when tracking must not happen (opt-out or non-production). - * - * @param array $input Resolved environment variables - * @param array $account Administrator account details - * @return array|null - */ - public function buildSelfHostedInstallPayload(array $input, bool $isUpgrade, string $version, array $account = []): ?array - { - if ($this->isTelemetryDisabled()) { - return null; - } - $appEnv = $input['_APP_ENV'] ?? 'development'; $domain = $input['_APP_DOMAIN'] ?? 'localhost'; /* local or test instance */ if ($appEnv !== 'production') { - return null; + return; } /* prod but local or test instance */ @@ -898,7 +871,7 @@ class Install extends Action || str_starts_with($domain, '127.') || str_starts_with($domain, '0.0.0.0') ) { - return null; + return; } $type = $isUpgrade ? 'upgrade' : 'install'; @@ -908,7 +881,7 @@ class Install extends Action $hostIp = @gethostbyname($domain); - return [ + $payload = [ 'action' => $type, 'account' => 'self-hosted', 'url' => 'https://' . $domain, @@ -927,18 +900,17 @@ class Install extends Action 'ram' => (int) round(((float) trim((string) \shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\''))) / 1024), ]), ]; - } - /** - * Whether the operator opted out of install/upgrade telemetry. - * - * Honors DO_NOT_TRACK (https://donottrack.sh/). - */ - public function isTelemetryDisabled(): bool - { - $doNotTrack = \strtolower((string) System::getEnv('DO_NOT_TRACK', '')); - - return \in_array($doNotTrack, ['1', 'true', 'yes'], true); + try { + $client = new Client(); + $client + ->setConnectTimeout(5000) + ->setTimeout(5000) + ->addHeader('Content-Type', 'application/json') + ->fetch(self::GROWTH_API_URL . '/analytics', Client::METHOD_POST, $payload); + } catch (\Throwable) { + // tracking shouldn't block installation + } } /** diff --git a/tests/unit/Platform/Tasks/InstallTest.php b/tests/unit/Platform/Tasks/InstallTest.php deleted file mode 100644 index cb27fa349e..0000000000 --- a/tests/unit/Platform/Tasks/InstallTest.php +++ /dev/null @@ -1,124 +0,0 @@ -install = new Install(); - } - - protected function tearDown(): void - { - \putenv('DO_NOT_TRACK'); - } - - /** - * @return array - */ - private function productionInput(): array - { - return [ - '_APP_ENV' => 'production', - '_APP_DOMAIN' => 'example.com', - '_APP_DB_ADAPTER' => 'mariadb', - ]; - } - - /** - * @return array - */ - private function account(): array - { - return [ - 'name' => 'Jane Admin', - 'email' => 'jane@example.com', - ]; - } - - public function testPayloadIncludesAdminNameAndEmail(): void - { - $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account()); - - $this->assertIsArray($payload); - $this->assertSame('install', $payload['action']); - $this->assertSame('self-hosted', $payload['account']); - $this->assertSame('1.9.6', $payload['version']); - - $data = \json_decode($payload['data'], true); - $this->assertIsArray($data); - - $this->assertSame('Jane Admin', $data['name']); - $this->assertSame('jane@example.com', $data['email']); - $this->assertSame('example.com', $data['domain']); - $this->assertSame('mariadb', $data['database']); - $this->assertArrayHasKey('os', $data); - $this->assertArrayHasKey('arch', $data); - } - - public function testUpgradeActionIsReported(): void - { - $payload = $this->install->buildSelfHostedInstallPayload($this->productionInput(), true, '1.9.6', $this->account()); - - $this->assertIsArray($payload); - $this->assertSame('upgrade', $payload['action']); - $this->assertSame('self_hosted_upgrade', $payload['label']); - } - - public function testDoNotTrackDisablesTelemetry(): void - { - \putenv('DO_NOT_TRACK=1'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account())); - } - - public function testDoNotTrackTrueValueDisablesTelemetry(): void - { - \putenv('DO_NOT_TRACK=true'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - } - - public function testDoNotTrackYesValueDisablesTelemetry(): void - { - \putenv('DO_NOT_TRACK=yes'); - - $this->assertTrue($this->install->isTelemetryDisabled()); - $this->assertNull($this->install->buildSelfHostedInstallPayload($this->productionInput(), false, '1.9.6', $this->account())); - } - - public function testTelemetryEnabledByDefault(): void - { - $this->assertFalse($this->install->isTelemetryDisabled()); - } - - public function testNonProductionEnvironmentIsNotTracked(): void - { - $input = $this->productionInput(); - $input['_APP_ENV'] = 'development'; - - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6', $this->account())); - } - - public function testLocalhostDomainIsNotTracked(): void - { - $input = $this->productionInput(); - $input['_APP_DOMAIN'] = 'localhost'; - - $this->assertNull($this->install->buildSelfHostedInstallPayload($input, false, '1.9.6', $this->account())); - } -}