Merge pull request #4039 from God-2077/umami-v3-dev-2

fix: Optimize IP detection logic and add error handling
This commit is contained in:
Mike Cao
2026-05-14 05:53:05 -04:00
committed by GitHub
+16 -16
View File
@@ -142,31 +142,31 @@ export async function getClientInfo(request: Request, payload: Record<string, an
export function hasBlockedIp(clientIp: string) {
const ignoreIps = process.env.IGNORE_IP;
if (ignoreIps) {
const ips = [];
if (!clientIp || !ignoreIps) {
return false;
}
if (ignoreIps) {
ips.push(...ignoreIps.split(',').map(n => n.trim()));
const ips = ignoreIps.split(',').map(n => n.trim());
return ips.some(ip => {
if (ip === clientIp) {
return true;
}
return ips.find(ip => {
if (ip === clientIp) {
return true;
}
// CIDR notation
if (ip.indexOf('/') > 0) {
// CIDR notation
if (ip.indexOf('/') > 0) {
try {
const addr = ipaddr.parse(clientIp);
const range = ipaddr.parseCIDR(ip);
if (addr.kind() === range[0].kind() && addr.match(range)) {
return true;
}
} catch {
// Ignore parsing errors
}
}
return false;
});
}
return false;
return false;
});
}