mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Merge pull request #3627 from malwarepad/master
URGENT! Resolve IPv6 address destruction on GeoIP query
This commit is contained in:
commit
3a4f4c1e27
1 changed files with 9 additions and 1 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue