From 1cd4b89d3b9e71abf2487ae118ac4b944f26c5a7 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 29 Jul 2026 16:35:19 +0530 Subject: [PATCH] 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())); } }