chore(geo): address review — drop dead asset, restore casing & denylist behavior

- Remove orphaned MaxMind asset app/assets/dbip/dbip-country-lite-2026-06.mmdb
  (no longer referenced after switch to the geo service).
- Store session countryCode lowercase again to preserve the pre-geo-service
  API value; /v1/locale and x-appwrite-country-code headers stay uppercase as before.
- Restore console denylist fail-open behavior: a missing/unknown geo lookup ("--")
  is allowed through to the membership check, matching pre-geo-service behavior.
  Remove the now-unused lookupSucceeded plumbing from GeoRecord and getGeoForIp.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Damodar LohaniandClaude Opus 4.8 committed 2026-07-07 11:07:34 +05:45
1 parent 5aaa043ce5
commit 389e5295cb
7 files changed
+9 -39

No files matched your search

Binary file not shown.
+4 -4
View File
@@ -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(),
+1 -1
View File
@@ -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(),
+2 -10
View File
@@ -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)) {
+1 -4
View File
@@ -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);
};
}, []);
};
-19
View File
@@ -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', '--') === '--';
@@ -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()));