Skip to content

Stealth Chromium that passes every bot detection test. Drop-in Playwright replacement with source-level fingerprint patches. 50+ tests passed.

fix(geoip): fall back to en-US for unmapped countries (#591)

CloakHQ2571290992d3
diff --git a/cloakbrowser/geoip.py b/cloakbrowser/geoip.py
index 319e2a5..f834d75 100644
--- a/cloakbrowser/geoip.py
+++ b/cloakbrowser/geoip.py
@@ -140,6 +140,10 @@ def resolve_proxy_geo_with_ip(
timezone = resp.location.time_zone
country = resp.country.iso_code
locale = COUNTRY_LOCALE_MAP.get(country) if country else None
+ if locale is None:
+ # Map gap, not a lookup failure — don't abort the launch over it
+ logger.warning("GeoIP: no locale for country %s (IP %s), using en-US", country, ip)
+ locale = "en-US"
logger.debug(
"GeoIP: %s → tz=%s, country=%s, locale=%s",
ip, timezone, country, locale,
diff --git a/dotnet/src/CloakBrowser/GeoIp.cs b/dotnet/src/CloakBrowser/GeoIp.cs
index 8fc7a5e..ee8e00c 100644
--- a/dotnet/src/CloakBrowser/GeoIp.cs
+++ b/dotnet/src/CloakBrowser/GeoIp.cs
@@ -131,6 +131,12 @@ public static class GeoIp
var timezone = resp.Location?.TimeZone;
var country = resp.Country?.IsoCode;
string? locale = country != null && CountryLocaleMap.TryGetValue(country, out var l) ? l : null;
+ if (locale == null)
+ {
+ // Map gap, not a lookup failure — don't abort the launch over it
+ CloakLog.Warning("GeoIP: no locale for country {0} (IP {1}), using en-US", country, ip);
+ locale = "en-US";
+ }
CloakLog.Debug("GeoIP: {0} -> tz={1}, country={2}, locale={3}", ip, timezone, country, locale);
return (timezone, locale, ip);
}
diff --git a/js/src/geoip.ts b/js/src/geoip.ts
index 608adf5..e5e5248 100644
--- a/js/src/geoip.ts
+++ b/js/src/geoip.ts
@@ -125,8 +125,13 @@ export async function resolveProxyGeo(
const result = reader.get(ip) as any;
const timezone: string | null = result?.location?.time_zone ?? null;
const countryCode: string | null = result?.country?.iso_code ?? null;
- const locale =
+ let locale =
countryCode ? (COUNTRY_LOCALE_MAP[countryCode] ?? null) : null;
+ if (locale === null) {
+ // Map gap, not a lookup failure — don't abort the launch over it
+ console.warn(`[cloakbrowser] GeoIP: no locale for country ${countryCode} (IP ${ip}), using en-US`);
+ locale = "en-US";
+ }
return { timezone, locale, exitIp: ip };
} catch (error) {
const detail = error instanceof Error ? error.message : String(error);
diff --git a/js/tests/geoip.test.ts b/js/tests/geoip.test.ts
index 46f1835..7529e29 100644
--- a/js/tests/geoip.test.ts
+++ b/js/tests/geoip.test.ts
@@ -181,6 +181,36 @@ describe("maybeResolveGeoip", () => {
await expect(resolveProxyGeo(null)).rejects.toThrow("GeoIP lookup failed");
});
+ it("falls back to en-US for a country missing from the locale map (#591)", async () => {
+ const cacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "cloak-geoip-unmapped-"));
+ tempDirs.push(cacheDir);
+ const geoipDir = path.join(cacheDir, "geoip");
+ fs.mkdirSync(geoipDir, { recursive: true });
+ fs.writeFileSync(path.join(geoipDir, "GeoLite2-City.mmdb"), "stub");
+ process.env.CLOAKBROWSER_CACHE_DIR = cacheDir;
+
+ class Reader {
+ get() {
+ return { location: { time_zone: "Indian/Mahe" }, country: { iso_code: "XX" } };
+ }
+ }
+ vi.doMock("mmdb-lib", () => ({ default: { Reader }, Reader }));
+ vi.spyOn(globalThis, "fetch").mockResolvedValue({
+ ok: true,
+ text: async () => "5.6.7.8",
+ } as Response);
+
+ try {
+ await expect(resolveProxyGeo(null)).resolves.toEqual({
+ timezone: "Indian/Mahe",
+ locale: "en-US",
+ exitIp: "5.6.7.8",
+ });
+ } finally {
+ vi.doUnmock("mmdb-lib");
+ }
+ });
+
it("downloads the database once under concurrent first-use launches (#458)", async () => {
const cacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "cloak-geoip-concurrent-"));
tempDirs.push(cacheDir);
diff --git a/tests/test_geoip.py b/tests/test_geoip.py
index 4768768..2cee178 100644
--- a/tests/test_geoip.py
+++ b/tests/test_geoip.py
@@ -128,6 +128,23 @@ def test_resolve_geo_raises_when_db_missing():
resolve_proxy_geo_with_ip("http://10.50.96.5:8888")
+def test_resolve_geo_unmapped_country_falls_back_to_en_us():
+ """A country missing from COUNTRY_LOCALE_MAP must not abort the launch (#591)."""
+ resp = MagicMock()
+ resp.location.time_zone = "Indian/Mahe"
+ resp.country.iso_code = "XX"
+ reader = MagicMock()
+ reader.return_value.__enter__.return_value.city.return_value = resp
+ mock_geoip2 = type("module", (), {"database": type("db", (), {"Reader": reader})})()
+ with patch.dict("sys.modules", {"geoip2": mock_geoip2, "geoip2.database": mock_geoip2.database}):
+ with patch("cloakbrowser.geoip._ensure_geoip_db", return_value=object()):
+ with patch("cloakbrowser.geoip._resolve_exit_ip", return_value="9.8.7.6"):
+ from cloakbrowser.geoip import resolve_proxy_geo_with_ip
+ assert resolve_proxy_geo_with_ip("http://10.50.96.5:8888") == (
+ "Indian/Mahe", "en-US", "9.8.7.6",
+ )
+
+
def test_resolve_geo_raises_when_lookup_fails():
"""A corrupt or unreadable database must abort requested GeoIP resolution."""
reader = MagicMock(side_effect=ValueError("corrupt database"))