Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Resolve IPv6 address destruction

Panagiotis7d9fe30626a0
diff --git a/src/lib/detect.ts b/src/lib/detect.ts
index ee9d2603c..17fb574c0 100644
--- a/src/lib/detect.ts
+++ b/src/lib/detect.ts
@@ -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) {