diff --git a/app/assets/dbip/dbip-country-lite-2026-06.mmdb b/app/assets/dbip/dbip-country-lite-2026-06.mmdb deleted file mode 100644 index df09a565b3..0000000000 Binary files a/app/assets/dbip/dbip-country-lite-2026-06.mmdb and /dev/null differ diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index b86d62a53d..bde3ff427b 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -169,7 +169,7 @@ $createSession = function (string $userId, string $secret, Request $request, Res 'userAgent' => $request->getUserAgent('UNKNOWN'), 'ip' => $request->getIP(), 'factors' => [$factor], - 'countryCode' => $geoRecord->getCountryCode(), + 'countryCode' => \strtolower($geoRecord->getCountryCode()), 'continentCode' => $geoRecord->getContinentCode() === '--' ? null : $geoRecord->getContinentCode(), 'latitude' => $geoRecord->getLatitude(), 'longitude' => $geoRecord->getLongitude(), @@ -988,7 +988,7 @@ Http::post('/v1/account/sessions/email') 'userAgent' => $request->getUserAgent('UNKNOWN'), 'ip' => $request->getIP(), 'factors' => ['password'], - 'countryCode' => $geoRecord->getCountryCode(), + 'countryCode' => \strtolower($geoRecord->getCountryCode()), 'continentCode' => $geoRecord->getContinentCode() === '--' ? null : $geoRecord->getContinentCode(), 'latitude' => $geoRecord->getLatitude(), 'longitude' => $geoRecord->getLongitude(), @@ -1173,7 +1173,7 @@ Http::post('/v1/account/sessions/anonymous') 'userAgent' => $request->getUserAgent('UNKNOWN'), 'ip' => $request->getIP(), 'factors' => ['anonymous'], - 'countryCode' => $geoRecord->getCountryCode(), + 'countryCode' => \strtolower($geoRecord->getCountryCode()), 'continentCode' => $geoRecord->getContinentCode() === '--' ? null : $geoRecord->getContinentCode(), 'latitude' => $geoRecord->getLatitude(), 'longitude' => $geoRecord->getLongitude(), @@ -1987,7 +1987,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') 'userAgent' => $request->getUserAgent('UNKNOWN'), 'ip' => $request->getIP(), 'factors' => [TYPE::EMAIL, 'oauth2'], // include a special oauth2 factor to bypass MFA checks - 'countryCode' => $geoRecord->getCountryCode(), + 'countryCode' => \strtolower($geoRecord->getCountryCode()), 'continentCode' => $geoRecord->getContinentCode() === '--' ? null : $geoRecord->getContinentCode(), 'latitude' => $geoRecord->getLatitude(), 'longitude' => $geoRecord->getLongitude(), diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 16b019f6a8..f61f0b6e4f 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -2314,7 +2314,7 @@ Http::post('/v1/users/:userId/sessions') 'userAgent' => $request->getUserAgent('UNKNOWN'), 'factors' => ['server'], 'ip' => $request->getIP(), - 'countryCode' => $geoRecord->getCountryCode(), + 'countryCode' => \strtolower($geoRecord->getCountryCode()), 'expire' => $expire, ], $detector->getOS(), diff --git a/app/controllers/shared/api/auth.php b/app/controllers/shared/api/auth.php index a8ad13e043..676b15f30e 100644 --- a/app/controllers/shared/api/auth.php +++ b/app/controllers/shared/api/auth.php @@ -42,16 +42,8 @@ Http::init() ->action(function (Route $route, Request $request, Document $project, GeoRecord $geoRecord, User $user, Authorization $authorization) { $denylist = System::getEnv('_APP_CONSOLE_COUNTRIES_DENYLIST', ''); if (!empty($denylist) && $project->getId() === 'console') { - // Fail-closed when we could not reach the geo service at all: we cannot prove - // the caller is outside a "block these countries" policy, so deny access - // rather than silently letting the denylist pass. A successful lookup that - // returns "--" (IP genuinely unknown to the geo DB, common for private and - // documentation ranges) is treated as allowed and falls through to the - // membership check below. - if (!$geoRecord->isLookupSucceeded()) { - throw new Exception(Exception::GENERAL_REGION_ACCESS_DENIED); - } - + // A missing or unknown geo lookup ("--") is treated as allowed and falls + // through to the membership check below, matching the pre-geo-service behavior. $countries = \array_map('strtoupper', \array_map('trim', explode(',', $denylist))); $country = \strtoupper($geoRecord->getCountryCode()); if (in_array($country, $countries, true)) { diff --git a/app/init/resources/request.php b/app/init/resources/request.php index f1f17f3930..4e4fdea46d 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -1351,7 +1351,6 @@ return function (Container $context): void { $context->set('getGeoForIp', function () { return function (Locale $locale, string $ip): GeoRecord { $record = null; - $lookupSucceeded = false; $geoEndpoint = System::getEnv('_APP_GEO_ENDPOINT', ''); $geoSecret = System::getEnv('_APP_GEO_SECRET', ''); @@ -1366,7 +1365,6 @@ return function (Container $context): void { $body = $response->json(); if (\is_array($body)) { $record = $body; - $lookupSucceeded = true; } } } catch (\Throwable $th) { @@ -1410,8 +1408,7 @@ return function (Container $context): void { 'connectionOrganization' => $record['organization'] ?? null, 'isp' => $record['isp'] ?? null, ])) - ->setLocale($locale) - ->setLookupSucceeded($lookupSucceeded); + ->setLocale($locale); }; }, []); }; diff --git a/src/Appwrite/Locale/GeoRecord.php b/src/Appwrite/Locale/GeoRecord.php index 0e88ecb2d5..a6aed647eb 100644 --- a/src/Appwrite/Locale/GeoRecord.php +++ b/src/Appwrite/Locale/GeoRecord.php @@ -9,8 +9,6 @@ class GeoRecord extends Document { private ?Locale $locale = null; - private bool $lookupSucceeded = false; - public function setLocale(Locale $locale): self { $this->locale = $locale; @@ -18,23 +16,6 @@ class GeoRecord extends Document return $this; } - public function setLookupSucceeded(bool $succeeded): self - { - $this->lookupSucceeded = $succeeded; - - return $this; - } - - /** - * True when the geo service returned a well-formed response for this IP, - * even if the response reported an unknown country (e.g. IP not in the DB). - * False when the service was unreachable, misconfigured, or errored. - */ - public function isLookupSucceeded(): bool - { - return $this->lookupSucceeded; - } - public function isEmpty(): bool { return $this->getAttribute('countryCode', '--') === '--'; diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php index be4f4f00ae..28be0ca958 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php @@ -151,7 +151,7 @@ class Update extends Action 'userAgent' => $request->getUserAgent('UNKNOWN'), 'ip' => $request->getIP(), 'factors' => ['email'], - 'countryCode' => $geoRecord->getCountryCode(), + 'countryCode' => \strtolower($geoRecord->getCountryCode()), 'expire' => DateTime::addSeconds(new \DateTime(), $authDuration) ], $detector->getOS(), $detector->getClient(), $detector->getDevice()));