Resolve IPv6 address destruction
This commit is contained in:
@@ -108,6 +108,14 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
|
|||||||
return Buffer.from(s, 'latin1').toString('utf-8');
|
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) {
|
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
|
||||||
// Ignore local ips
|
// Ignore local ips
|
||||||
if (await isLocalhost(ip)) {
|
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
|
// 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);
|
const result = global[MAXMIND].get(cleanIp);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
Reference in New Issue
Block a user