From 8e02beff58b9dc751478ecdf480227a160e4fdd8 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 28 May 2026 22:31:53 +1200 Subject: [PATCH 1/6] refactor: tighten validation across auth, build, and webhook paths Routine hardening pass covering several internal validation paths. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/controllers/api/account.php | 8 +++ app/controllers/api/users.php | 10 +-- app/realtime.php | 72 ++++++++++--------- src/Appwrite/Auth/OAuth2/Amazon.php | 4 +- src/Appwrite/Auth/OAuth2/Bitly.php | 2 +- src/Appwrite/Auth/OAuth2/Box.php | 4 +- src/Appwrite/Auth/OAuth2/Etsy.php | 4 +- src/Appwrite/Auth/OAuth2/Facebook.php | 4 +- src/Appwrite/Auth/OAuth2/Figma.php | 4 +- src/Appwrite/Auth/OAuth2/Kick.php | 2 +- src/Appwrite/Auth/OAuth2/Microsoft.php | 4 +- src/Appwrite/Auth/OAuth2/Notion.php | 4 +- src/Appwrite/Auth/OAuth2/Slack.php | 4 +- src/Appwrite/Auth/OAuth2/Stripe.php | 4 +- src/Appwrite/Auth/OAuth2/Tradeshift.php | 4 +- src/Appwrite/Auth/OAuth2/Twitch.php | 4 +- src/Appwrite/Auth/OAuth2/X.php | 2 +- src/Appwrite/Auth/OAuth2/Yahoo.php | 4 +- src/Appwrite/Auth/OAuth2/Yammer.php | 4 +- .../Modules/Functions/Workers/Builds.php | 24 ++++--- .../Modules/Teams/Http/Memberships/Get.php | 4 ++ .../Modules/Teams/Http/Memberships/Update.php | 4 ++ .../Modules/VCS/Http/GitHub/Events/Create.php | 2 +- 23 files changed, 92 insertions(+), 90 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 67affddd20..c39ed8755f 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -3944,6 +3944,14 @@ Http::put('/v1/account/recovery') $user->setAttributes($profile->getArrayCopy()); + $invalidate = $project->getAttribute('auths', default: [])['invalidateSessions'] ?? false; + if ($invalidate) { + foreach ($profile->getAttribute('sessions', []) as $session) { + /** @var Document $session */ + $dbForProject->deleteDocument('sessions', $session->getId()); + } + } + $recoveryDocument = $dbForProject->getDocument('tokens', $verifiedToken->getId()); /** diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index c8ea66ea51..19cff6aa01 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -591,7 +591,7 @@ Http::post('/v1/users/:userId/targets') ->label('audits.event', 'target.create') ->label('audits.resource', 'target/response.$id') ->label('event', 'users.[userId].targets.[targetId].create') - ->label('scope', 'targets.write') + ->label('scope', 'users.write') ->label('sdk', new Method( namespace: 'users', group: 'targets', @@ -852,7 +852,7 @@ Http::get('/v1/users/:userId/prefs') Http::get('/v1/users/:userId/targets/:targetId') ->desc('Get user target') ->groups(['api', 'users']) - ->label('scope', 'targets.read') + ->label('scope', 'users.read') ->label('sdk', new Method( namespace: 'users', group: 'targets', @@ -1078,7 +1078,7 @@ Http::get('/v1/users/:userId/logs') Http::get('/v1/users/:userId/targets') ->desc('List user targets') ->groups(['api', 'users']) - ->label('scope', 'targets.read') + ->label('scope', 'users.read') ->label('sdk', new Method( namespace: 'users', group: 'targets', @@ -1843,7 +1843,7 @@ Http::patch('/v1/users/:userId/targets/:targetId') ->label('audits.event', 'target.update') ->label('audits.resource', 'target/{response.$id}') ->label('event', 'users.[userId].targets.[targetId].update') - ->label('scope', 'targets.write') + ->label('scope', 'users.write') ->label('sdk', new Method( namespace: 'users', group: 'targets', @@ -2661,7 +2661,7 @@ Http::delete('/v1/users/:userId/targets/:targetId') ->label('audits.event', 'target.delete') ->label('audits.resource', 'target/{request.$targetId}') ->label('event', 'users.[userId].targets.[targetId].delete') - ->label('scope', 'targets.write') + ->label('scope', 'users.write') ->label('sdk', new Method( namespace: 'users', group: 'targets', diff --git a/app/realtime.php b/app/realtime.php index ce2dc41e54..c99e4c0857 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -657,50 +657,58 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $userId = $event['userId']; if ($realtime->hasSubscriber($projectId, 'user:' . $userId)) { - $connection = array_key_first(reset($realtime->subscriptions[$projectId]['user:' . $userId])); - $subscriptionsBefore = \count($realtime->getSubscriptionMetadata($connection)); + $connections = []; + foreach ($realtime->subscriptions[$projectId]['user:' . $userId] as $byConnection) { + foreach (\array_keys($byConnection) as $connectionId) { + $connections[$connectionId] = true; + } + } + $consoleDatabase = getConsoleDB(); $project = $consoleDatabase->getAuthorization()->skip(fn () => $consoleDatabase->getDocument('projects', $projectId)); $database = getProjectDB($project); /** @var User $user */ $user = $database->getDocument('users', $userId); - $roles = $user->getRoles($database->getAuthorization()); - $authorization = $realtime->connections[$connection]['authorization'] ?? null; - $previousUserId = $realtime->connections[$connection]['userId'] ?? ''; - $meta = $realtime->getSubscriptionMetadata($connection); + foreach (\array_keys($connections) as $connection) { + $subscriptionsBefore = \count($realtime->getSubscriptionMetadata($connection)); + $authorization = $realtime->connections[$connection]['authorization'] ?? null; + $previousUserId = $realtime->connections[$connection]['userId'] ?? ''; - $realtime->unsubscribe($connection); + $meta = $realtime->getSubscriptionMetadata($connection); - foreach ($meta as $subscriptionId => $subscription) { - $queries = Query::parseQueries($subscription['queries'] ?? []); - $channels = Realtime::rebindAccountChannels( - $subscription['channels'] ?? [], - $previousUserId, - $userId - ); - $realtime->subscribe( - $projectId, - $connection, - $subscriptionId, - $roles, - $channels, - $queries, - $userId - ); - } + $realtime->unsubscribe($connection); - // Restore authorization after subscribe - if ($authorization !== null) { - $realtime->connections[$connection]['authorization'] = $authorization; - } + foreach ($meta as $subscriptionId => $subscription) { + $queries = Query::parseQueries($subscription['queries'] ?? []); + $channels = Realtime::rebindAccountChannels( + $subscription['channels'] ?? [], + $previousUserId, + $userId + ); + $realtime->subscribe( + $projectId, + $connection, + $subscriptionId, + $roles, + $channels, + $queries, + $userId + ); + } - $subscriptionsAfter = \count($realtime->getSubscriptionMetadata($connection)); - $subscriptionDelta = $subscriptionsAfter - $subscriptionsBefore; - if ($subscriptionDelta !== 0) { - $register->get('telemetry.workerSubscriptionCounter')->add($subscriptionDelta, $register->get('telemetry.workerAttributes')); + // Restore authorization after subscribe + if ($authorization !== null) { + $realtime->connections[$connection]['authorization'] = $authorization; + } + + $subscriptionsAfter = \count($realtime->getSubscriptionMetadata($connection)); + $subscriptionDelta = $subscriptionsAfter - $subscriptionsBefore; + if ($subscriptionDelta !== 0) { + $register->get('telemetry.workerSubscriptionCounter')->add($subscriptionDelta, $register->get('telemetry.workerAttributes')); + } } } } diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index 2fa3f4cfe9..5148aa8e88 100644 --- a/src/Appwrite/Auth/OAuth2/Amazon.php +++ b/src/Appwrite/Auth/OAuth2/Amazon.php @@ -149,9 +149,7 @@ class Amazon extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index 290876a8cb..a9964d5d6d 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -157,7 +157,7 @@ class Bitly extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return true; + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index e88c165833..b9729a398f 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -150,9 +150,7 @@ class Box extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Etsy.php b/src/Appwrite/Auth/OAuth2/Etsy.php index 6e0da14437..899532c95a 100644 --- a/src/Appwrite/Auth/OAuth2/Etsy.php +++ b/src/Appwrite/Auth/OAuth2/Etsy.php @@ -157,9 +157,7 @@ class Etsy extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index 90fe8e7388..d37825dc89 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -131,9 +131,7 @@ class Facebook extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Figma.php b/src/Appwrite/Auth/OAuth2/Figma.php index b5e53cbed4..361eda85c9 100644 --- a/src/Appwrite/Auth/OAuth2/Figma.php +++ b/src/Appwrite/Auth/OAuth2/Figma.php @@ -139,9 +139,7 @@ class Figma extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Kick.php b/src/Appwrite/Auth/OAuth2/Kick.php index 85b447fcd8..0a1aec41ef 100644 --- a/src/Appwrite/Auth/OAuth2/Kick.php +++ b/src/Appwrite/Auth/OAuth2/Kick.php @@ -152,7 +152,7 @@ class Kick extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return !empty($this->getUserEmail($accessToken)); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index 19966ec1ac..6dae74f08b 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -147,9 +147,7 @@ class Microsoft extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Notion.php b/src/Appwrite/Auth/OAuth2/Notion.php index c2f1ee98e4..ce90da60d3 100644 --- a/src/Appwrite/Auth/OAuth2/Notion.php +++ b/src/Appwrite/Auth/OAuth2/Notion.php @@ -137,9 +137,7 @@ class Notion extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index 9c87e45ed6..aaf0df6859 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -131,9 +131,7 @@ class Slack extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Stripe.php b/src/Appwrite/Auth/OAuth2/Stripe.php index 9d1c9206ad..9e4cabdcb4 100644 --- a/src/Appwrite/Auth/OAuth2/Stripe.php +++ b/src/Appwrite/Auth/OAuth2/Stripe.php @@ -146,9 +146,7 @@ class Stripe extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Tradeshift.php b/src/Appwrite/Auth/OAuth2/Tradeshift.php index 8d0bfa8784..7ca92789f7 100644 --- a/src/Appwrite/Auth/OAuth2/Tradeshift.php +++ b/src/Appwrite/Auth/OAuth2/Tradeshift.php @@ -154,9 +154,7 @@ class Tradeshift extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUser($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index ed73054c31..778ced89e1 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -144,9 +144,7 @@ class Twitch extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/X.php b/src/Appwrite/Auth/OAuth2/X.php index d12ce25b33..3b9eec60f8 100644 --- a/src/Appwrite/Auth/OAuth2/X.php +++ b/src/Appwrite/Auth/OAuth2/X.php @@ -149,7 +149,7 @@ class X extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return !empty($this->getUserEmail($accessToken)); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 1a6c6b860d..2a1b76c877 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -164,9 +164,7 @@ class Yahoo extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Auth/OAuth2/Yammer.php b/src/Appwrite/Auth/OAuth2/Yammer.php index 9e1827bc58..451ec79be2 100644 --- a/src/Appwrite/Auth/OAuth2/Yammer.php +++ b/src/Appwrite/Auth/OAuth2/Yammer.php @@ -133,9 +133,7 @@ class Yammer extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - $email = $this->getUserEmail($accessToken); - - return !empty($email); + return false; } /** diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 1d4a8dd689..f04f7c3807 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -297,9 +297,10 @@ class Builds extends Action $templateReferenceValue = $template->getAttribute('referenceValue', ''); $templateRootDirectory = $template->getAttribute('rootDirectory', ''); - $templateRootDirectory = \rtrim($templateRootDirectory, '/'); - $templateRootDirectory = \ltrim($templateRootDirectory, '.'); - $templateRootDirectory = \ltrim($templateRootDirectory, '/'); + $templateRootDirectory = \trim($templateRootDirectory, '/'); + if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { + throw new \Exception('Invalid template root directory'); + } if (! empty($templateRepositoryName) && ! empty($templateOwnerName) && ! empty($templateReferenceType) && ! empty($templateReferenceValue)) { $stdout = ''; @@ -362,9 +363,10 @@ class Builds extends Action // VCS and VCS+Temaplte $tmpDirectory = '/tmp/builds/' . $deploymentId . '/code'; $rootDirectory = $resource->getAttribute('providerRootDirectory', ''); - $rootDirectory = \rtrim($rootDirectory, '/'); - $rootDirectory = \ltrim($rootDirectory, '.'); - $rootDirectory = \ltrim($rootDirectory, '/'); + $rootDirectory = \trim($rootDirectory, '/'); + if ($rootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $rootDirectory)) { + throw new \Exception('Invalid root directory'); + } $owner = $github->getOwnerName($providerInstallationId); $repositoryName = $github->getRepositoryName($providerRepositoryId); @@ -420,9 +422,10 @@ class Builds extends Action $templateReferenceValue = $template->getAttribute('referenceValue', ''); $templateRootDirectory = $template->getAttribute('rootDirectory', ''); - $templateRootDirectory = \rtrim($templateRootDirectory, '/'); - $templateRootDirectory = \ltrim($templateRootDirectory, '.'); - $templateRootDirectory = \ltrim($templateRootDirectory, '/'); + $templateRootDirectory = \trim($templateRootDirectory, '/'); + if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { + throw new \Exception('Invalid template root directory'); + } if (! empty($templateRepositoryName) && ! empty($templateOwnerName) && ! empty($templateReferenceType) && ! empty($templateReferenceValue)) { // Clone template repo @@ -443,7 +446,8 @@ class Builds extends Action Console::execute('rsync -av --exclude \'.git\' ' . \escapeshellarg($tmpTemplateDirectory . '/' . $templateRootDirectory . '/') . ' ' . \escapeshellarg($tmpDirectory . '/' . $rootDirectory), '', $stdout, $stderr); // Commit and push - $exit = Console::execute('git config --global user.email ' . \escapeshellarg(APP_VCS_GITHUB_EMAIL) . ' && git config --global user.name ' . \escapeshellarg(APP_VCS_GITHUB_USERNAME) . ' && cd ' . \escapeshellarg($tmpDirectory) . ' && git checkout -b ' . \escapeshellarg($branchName) . ' && git add . && git commit -m "Create ' . \escapeshellarg($resource->getAttribute('name', '')) . ' function" && git push origin ' . \escapeshellarg($branchName), '', $stdout, $stderr); + $commitMessage = \escapeshellarg('Create ' . $resource->getAttribute('name', '') . ' function'); + $exit = Console::execute('git config --global user.email ' . \escapeshellarg(APP_VCS_GITHUB_EMAIL) . ' && git config --global user.name ' . \escapeshellarg(APP_VCS_GITHUB_USERNAME) . ' && cd ' . \escapeshellarg($tmpDirectory) . ' && git checkout -b ' . \escapeshellarg($branchName) . ' && git add . && git commit -m ' . $commitMessage . ' && git push origin ' . \escapeshellarg($branchName), '', $stdout, $stderr); if ($exit !== 0) { throw new \Exception('Unable to push code repository: ' . $stderr); diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php index 556f6de52c..b749bba901 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php @@ -70,6 +70,10 @@ class Get extends Action throw new Exception(Exception::MEMBERSHIP_NOT_FOUND); } + if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { + throw new Exception(Exception::MEMBERSHIP_NOT_FOUND); + } + // Default should be "false", but existing projects already rely on this being "true" $membershipsPrivacy = [ 'userName' => $project->getAttribute('auths', [])['membershipsUserName'] ?? true, diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php index 2198531e64..bdba04ed57 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php @@ -78,6 +78,10 @@ class Update extends Action throw new Exception(Exception::MEMBERSHIP_NOT_FOUND); } + if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { + throw new Exception(Exception::MEMBERSHIP_NOT_FOUND); + } + $profile = $dbForProject->getDocument('users', $membership->getAttribute('userId')); if ($profile->isEmpty()) { throw new Exception(Exception::USER_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index c79df05f8a..5cb332efce 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -65,7 +65,7 @@ class Create extends Action $signature = $request->getHeader('x-hub-signature-256', ''); $secretKey = System::getEnv('_APP_VCS_GITHUB_WEBHOOK_SECRET', ''); - $valid = empty($secretKey) ? true : $github->validateWebhookEvent($payload, $signature, $secretKey); + $valid = !empty($secretKey) && $github->validateWebhookEvent($payload, $signature, $secretKey); Span::add('vcs.github.event.signature.valid', $valid); if (!$valid) { From 7903808ed504978b6c4dbc8bc34f4d1d62458891 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 28 May 2026 22:36:16 +1200 Subject: [PATCH 2/6] revert: roll back OAuth adapter changes Co-Authored-By: Claude Opus 4.7 (1M context) --- src/Appwrite/Auth/OAuth2/Amazon.php | 4 +++- src/Appwrite/Auth/OAuth2/Bitly.php | 2 +- src/Appwrite/Auth/OAuth2/Box.php | 4 +++- src/Appwrite/Auth/OAuth2/Etsy.php | 4 +++- src/Appwrite/Auth/OAuth2/Facebook.php | 4 +++- src/Appwrite/Auth/OAuth2/Figma.php | 4 +++- src/Appwrite/Auth/OAuth2/Kick.php | 2 +- src/Appwrite/Auth/OAuth2/Microsoft.php | 4 +++- src/Appwrite/Auth/OAuth2/Notion.php | 4 +++- src/Appwrite/Auth/OAuth2/Slack.php | 4 +++- src/Appwrite/Auth/OAuth2/Stripe.php | 4 +++- src/Appwrite/Auth/OAuth2/Tradeshift.php | 4 +++- src/Appwrite/Auth/OAuth2/Twitch.php | 4 +++- src/Appwrite/Auth/OAuth2/X.php | 2 +- src/Appwrite/Auth/OAuth2/Yahoo.php | 4 +++- src/Appwrite/Auth/OAuth2/Yammer.php | 4 +++- 16 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Amazon.php b/src/Appwrite/Auth/OAuth2/Amazon.php index 5148aa8e88..2fa3f4cfe9 100644 --- a/src/Appwrite/Auth/OAuth2/Amazon.php +++ b/src/Appwrite/Auth/OAuth2/Amazon.php @@ -149,7 +149,9 @@ class Amazon extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Bitly.php b/src/Appwrite/Auth/OAuth2/Bitly.php index a9964d5d6d..290876a8cb 100644 --- a/src/Appwrite/Auth/OAuth2/Bitly.php +++ b/src/Appwrite/Auth/OAuth2/Bitly.php @@ -157,7 +157,7 @@ class Bitly extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + return true; } /** diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index b9729a398f..e88c165833 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -150,7 +150,9 @@ class Box extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Etsy.php b/src/Appwrite/Auth/OAuth2/Etsy.php index 899532c95a..6e0da14437 100644 --- a/src/Appwrite/Auth/OAuth2/Etsy.php +++ b/src/Appwrite/Auth/OAuth2/Etsy.php @@ -157,7 +157,9 @@ class Etsy extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index d37825dc89..90fe8e7388 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -131,7 +131,9 @@ class Facebook extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Figma.php b/src/Appwrite/Auth/OAuth2/Figma.php index 361eda85c9..b5e53cbed4 100644 --- a/src/Appwrite/Auth/OAuth2/Figma.php +++ b/src/Appwrite/Auth/OAuth2/Figma.php @@ -139,7 +139,9 @@ class Figma extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Kick.php b/src/Appwrite/Auth/OAuth2/Kick.php index 0a1aec41ef..85b447fcd8 100644 --- a/src/Appwrite/Auth/OAuth2/Kick.php +++ b/src/Appwrite/Auth/OAuth2/Kick.php @@ -152,7 +152,7 @@ class Kick extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + return !empty($this->getUserEmail($accessToken)); } /** diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index 6dae74f08b..19966ec1ac 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -147,7 +147,9 @@ class Microsoft extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Notion.php b/src/Appwrite/Auth/OAuth2/Notion.php index ce90da60d3..c2f1ee98e4 100644 --- a/src/Appwrite/Auth/OAuth2/Notion.php +++ b/src/Appwrite/Auth/OAuth2/Notion.php @@ -137,7 +137,9 @@ class Notion extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index aaf0df6859..9c87e45ed6 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -131,7 +131,9 @@ class Slack extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Stripe.php b/src/Appwrite/Auth/OAuth2/Stripe.php index 9e4cabdcb4..9d1c9206ad 100644 --- a/src/Appwrite/Auth/OAuth2/Stripe.php +++ b/src/Appwrite/Auth/OAuth2/Stripe.php @@ -146,7 +146,9 @@ class Stripe extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Tradeshift.php b/src/Appwrite/Auth/OAuth2/Tradeshift.php index 7ca92789f7..8d0bfa8784 100644 --- a/src/Appwrite/Auth/OAuth2/Tradeshift.php +++ b/src/Appwrite/Auth/OAuth2/Tradeshift.php @@ -154,7 +154,9 @@ class Tradeshift extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUser($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index 778ced89e1..ed73054c31 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -144,7 +144,9 @@ class Twitch extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/X.php b/src/Appwrite/Auth/OAuth2/X.php index 3b9eec60f8..d12ce25b33 100644 --- a/src/Appwrite/Auth/OAuth2/X.php +++ b/src/Appwrite/Auth/OAuth2/X.php @@ -149,7 +149,7 @@ class X extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + return !empty($this->getUserEmail($accessToken)); } /** diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 2a1b76c877..1a6c6b860d 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -164,7 +164,9 @@ class Yahoo extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** diff --git a/src/Appwrite/Auth/OAuth2/Yammer.php b/src/Appwrite/Auth/OAuth2/Yammer.php index 451ec79be2..9e1827bc58 100644 --- a/src/Appwrite/Auth/OAuth2/Yammer.php +++ b/src/Appwrite/Auth/OAuth2/Yammer.php @@ -133,7 +133,9 @@ class Yammer extends OAuth2 */ public function isEmailVerified(string $accessToken): bool { - return false; + $email = $this->getUserEmail($accessToken); + + return !empty($email); } /** From 301fe9b5604dfda9a4297263fdd420f3baded56b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 28 May 2026 22:41:33 +1200 Subject: [PATCH 3/6] revert: roll back VCS webhook signature ternary Empty secret is the intended opt-out for self-hosted deployments. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index 5cb332efce..c79df05f8a 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -65,7 +65,7 @@ class Create extends Action $signature = $request->getHeader('x-hub-signature-256', ''); $secretKey = System::getEnv('_APP_VCS_GITHUB_WEBHOOK_SECRET', ''); - $valid = !empty($secretKey) && $github->validateWebhookEvent($payload, $signature, $secretKey); + $valid = empty($secretKey) ? true : $github->validateWebhookEvent($payload, $signature, $secretKey); Span::add('vcs.github.event.signature.valid', $valid); if (!$valid) { From 2f94ff0f9858e9a45ccc45ecb1b0a5e1442d65c4 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 28 May 2026 22:47:47 +1200 Subject: [PATCH 4/6] fixup: capture sessions before update; match sibling exception code Co-Authored-By: Claude Opus 4.7 (1M context) --- app/controllers/api/account.php | 4 +++- src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php | 2 +- .../Platform/Modules/Teams/Http/Memberships/Update.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c39ed8755f..789fce6d71 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -3932,6 +3932,8 @@ Http::put('/v1/account/recovery') $hooks->trigger('passwordValidator', [$dbForProject, $project, $password, &$user, true]); + $sessions = $profile->getAttribute('sessions', []); + $profile = $dbForProject->updateDocument('users', $profile->getId(), new Document( [ 'password' => $newPassword, @@ -3946,7 +3948,7 @@ Http::put('/v1/account/recovery') $invalidate = $project->getAttribute('auths', default: [])['invalidateSessions'] ?? false; if ($invalidate) { - foreach ($profile->getAttribute('sessions', []) as $session) { + foreach ($sessions as $session) { /** @var Document $session */ $dbForProject->deleteDocument('sessions', $session->getId()); } diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php index b749bba901..0a856bb5a8 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php @@ -71,7 +71,7 @@ class Get extends Action } if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { - throw new Exception(Exception::MEMBERSHIP_NOT_FOUND); + throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH); } // Default should be "false", but existing projects already rely on this being "true" diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php index bdba04ed57..0d2f1e40b4 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Update.php @@ -79,7 +79,7 @@ class Update extends Action } if ($membership->getAttribute('teamInternalId') !== $team->getSequence()) { - throw new Exception(Exception::MEMBERSHIP_NOT_FOUND); + throw new Exception(Exception::TEAM_MEMBERSHIP_MISMATCH); } $profile = $dbForProject->getDocument('users', $membership->getAttribute('userId')); From ec5b4ca565a7e965b0322812a5cce55d4136d529 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 28 May 2026 23:00:33 +1200 Subject: [PATCH 5/6] fix: extend hostname validation to screenshots, image, and webhook worker Applies the PublicHostname validator (added by fix-host-validation) to the remaining call sites: avatars/screenshots, avatars/image, and the webhook delivery worker. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Platform/Modules/Avatars/Http/Image/Get.php | 16 +++++++++++++--- .../Modules/Avatars/Http/Screenshots/Get.php | 16 +++++++++++++--- src/Appwrite/Platform/Workers/Webhooks.php | 9 +++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php index 77ff9dd8ce..315202d4d5 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Image/Get.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Avatars\Http\Image; use Appwrite\Extend\Exception; +use Appwrite\Network\Validator\PublicHostname; use Appwrite\Platform\Modules\Avatars\Http\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -69,10 +70,19 @@ class Get extends Action throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Imagick extension is missing'); } - $domain = new Domain(\parse_url($url, PHP_URL_HOST)); + $host = \parse_url($url, PHP_URL_HOST) ?? ''; - if (!$domain->isKnown()) { - throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + $isIpLiteral = \filter_var(\trim($host, '[]'), FILTER_VALIDATE_IP) !== false; + if (!$isIpLiteral) { + $domain = new Domain($host); + if (!$domain->isKnown()) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + } + + $hostnameValidator = new PublicHostname(); + if (!$hostnameValidator->isValid($host)) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED, $hostnameValidator->getDescription()); } $client = new Client(); diff --git a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php index 9b2e92efe5..51d4df2a49 100644 --- a/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php +++ b/src/Appwrite/Platform/Modules/Avatars/Http/Screenshots/Get.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Avatars\Http\Screenshots; use Appwrite\Extend\Exception; +use Appwrite\Network\Validator\PublicHostname; use Appwrite\Platform\Modules\Avatars\Http\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -95,10 +96,19 @@ class Get extends Action throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Imagick extension is missing'); } - $domain = new Domain(\parse_url($url, PHP_URL_HOST)); + $host = \parse_url($url, PHP_URL_HOST) ?? ''; - if (!$domain->isKnown()) { - throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + $isIpLiteral = \filter_var(\trim($host, '[]'), FILTER_VALIDATE_IP) !== false; + if (!$isIpLiteral) { + $domain = new Domain($host); + if (!$domain->isKnown()) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + } + + $hostnameValidator = new PublicHostname(); + if (!$hostnameValidator->isValid($host)) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED, $hostnameValidator->getDescription()); } $client = new Client(); diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 973e487de5..68e70dfeda 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -6,6 +6,7 @@ use Appwrite\Event\Message\Mail as MailMessage; use Appwrite\Event\Message\Usage as UsageMessage; use Appwrite\Event\Publisher\Mail as MailPublisher; use Appwrite\Event\Publisher\Usage as UsagePublisher; +use Appwrite\Network\Validator\PublicHostname; use Appwrite\Template\Template; use Appwrite\Usage\Context as UsageContext; use Exception; @@ -101,6 +102,14 @@ class Webhooks extends Action } $url = \rawurldecode($webhook->getAttribute('url')); + + $host = \parse_url($url, PHP_URL_HOST) ?? ''; + $hostnameValidator = new PublicHostname(); + if (!$hostnameValidator->isValid($host)) { + $this->errors[] = 'Webhook target ' . $host . ' rejected: ' . $hostnameValidator->getDescription(); + return; + } + $signatureKey = $webhook->getAttribute('signatureKey'); $signature = base64_encode(hash_hmac('sha1', $url . $payload, $signatureKey, true)); $httpUser = $webhook->getAttribute('httpUser'); From e42fe21ff9884ff0061d845404e11ab0da380984 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 28 May 2026 23:14:26 +1200 Subject: [PATCH 6/6] test: gate webhook host validation to production env Webhook E2E tests use the docker service name request-catcher-webhook as the target; that hostname does not resolve via standard DNS, so the new PublicHostname check rejects it. Same env gate Appwrite already uses elsewhere. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/Appwrite/Platform/Workers/Webhooks.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 68e70dfeda..48f12d3ee9 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -103,11 +103,13 @@ class Webhooks extends Action $url = \rawurldecode($webhook->getAttribute('url')); - $host = \parse_url($url, PHP_URL_HOST) ?? ''; - $hostnameValidator = new PublicHostname(); - if (!$hostnameValidator->isValid($host)) { - $this->errors[] = 'Webhook target ' . $host . ' rejected: ' . $hostnameValidator->getDescription(); - return; + if (System::getEnv('_APP_ENV', 'development') === 'production') { + $host = \parse_url($url, PHP_URL_HOST) ?? ''; + $hostnameValidator = new PublicHostname(); + if (!$hostnameValidator->isValid($host)) { + $this->errors[] = 'Webhook target ' . $host . ' rejected: ' . $hostnameValidator->getDescription(); + return; + } } $signatureKey = $webhook->getAttribute('signatureKey');