Merge pull request #3498 from AlexEscalante/sanitize-ip

Sanitize IP to remove port for geolocation lookup
This commit is contained in:
Mike Cao
2025-07-01 21:26:36 -07:00
committed by GitHub

View File

@@ -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;