Merge pull request #3627 from malwarepad/master

URGENT! Resolve IPv6 address destruction on GeoIP query
This commit is contained in:
Mike Cao 2025-09-22 22:26:33 -07:00 committed by GitHub
commit 3a4f4c1e27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -108,6 +108,14 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
return Buffer.from(s, 'latin1').toString('utf-8');
}
function removePortFromIP(ip: string = "") {
const split = ip.split(":");
// Assuming ip is a valid IPv4/IPv6 address, 3 colons is the minumum for IPv6
const ipv4 = split.length - 1 < 3;
return ipv4 ? split[0] : ip;
}
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
// Ignore local ips
if (await isLocalhost(ip)) {
@ -141,7 +149,7 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
}
// When the client IP is extracted from headers, sometimes the value includes a port
const cleanIp = ip?.split(':')[0];
const cleanIp = removePortFromIP(ip);
const result = global[MAXMIND].get(cleanIp);
if (result) {