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.
This commit is contained in:
Alex Escalante 2025-06-30 18:40:21 -06:00 committed by GitHub
parent 0c2070771b
commit 26ddfd5a80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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;