From a1802add192fd5d27861caebbbe271f514a3e902 Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 26 Aug 2025 17:14:55 -0700 Subject: [PATCH] Geoblocking works --- esbuild.mjs | 2 +- server/routers/badger/verifySession.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/esbuild.mjs b/esbuild.mjs index b0227099..d76c0753 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -63,7 +63,7 @@ esbuild packagePath: getPackagePaths(), }), ], - sourcemap: true, + sourcemap: "external", target: "node22", }) .then(() => { diff --git a/server/routers/badger/verifySession.ts b/server/routers/badger/verifySession.ts index 5f80de16..632d6fcc 100644 --- a/server/routers/badger/verifySession.ts +++ b/server/routers/badger/verifySession.ts @@ -753,6 +753,10 @@ export function isPathAllowed(pattern: string, path: string): boolean { } async function isIpInGeoIP(ip: string, countryCode: string): Promise { + if (countryCode == "ALL") { + return true; + } + const geoIpCacheKey = `geoip:${ip}`; let cachedCountryCode: string | undefined = cache.get(geoIpCacheKey); @@ -760,17 +764,15 @@ async function isIpInGeoIP(ip: string, countryCode: string): Promise { if (!cachedCountryCode) { try { const response = await axios.get( - `${config.getRawConfig().managed?.endpoint}/api/v1/geoip/${ip}`, + `${config.getRawConfig().managed?.endpoint}/api/v1/hybrid/geoip/${ip}`, await tokenManager.getAuthHeader() ); - cachedCountryCode = response.data.data.country; + cachedCountryCode = response.data.data.countryCode; // Cache for longer since IP geolocation doesn't change frequently cache.set(geoIpCacheKey, cachedCountryCode, 300); // 5 minutes - logger.debug(`IP ${ip} is in country:`, cachedCountryCode); - } catch (error) { if (axios.isAxiosError(error)) { logger.error("Error fetching config in verify session:", { @@ -788,5 +790,7 @@ async function isIpInGeoIP(ip: string, countryCode: string): Promise { } } + logger.debug(`IP ${ip} is in country: ${cachedCountryCode}`); + return cachedCountryCode?.toUpperCase() === countryCode.toUpperCase(); }