From 26ddfd5a80683b1750a821d87cadff781d8fa146 Mon Sep 17 00:00:00 2001 From: Alex Escalante <656454+AlexEscalante@users.noreply.github.com> Date: Mon, 30 Jun 2025 18:40:21 -0600 Subject: [PATCH] Sanitize IP to remove port for geolocation lookup Sanitize IP address to remove port number before geolocation lookup. This ensures proper MaxMind database resolution in setups where IP:PORT is passed by the proxy. --- src/lib/detect.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/detect.ts b/src/lib/detect.ts index a023d27d..ae750469 100644 --- a/src/lib/detect.ts +++ b/src/lib/detect.ts @@ -127,7 +127,9 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI global[MAXMIND] = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb')); } - const result = global[MAXMIND].get(ip); + // When the client IP is extracted from headers, sometimes the value includes a port + const cleanIp = ip?.split(':')[0]; + const result = global[MAXMIND].get(cleanIp); if (result) { const country = result.country?.iso_code ?? result?.registered_country?.iso_code;