Allow /stats from LAN/private IP ranges

This commit is contained in:
2026-03-26 13:34:33 +01:00
parent c5e9896e65
commit 0ec3222873
3 changed files with 40 additions and 2 deletions

View File

@@ -236,7 +236,44 @@ function getRequestIp(request) {
function isLocalRequest(request) {
const ip = getRequestIp(request);
return ip === '127.0.0.1' || ip === '::1' || ip === '';
if (!ip || ip === '127.0.0.1' || ip === '::1') {
return true;
}
if (ip.includes(':')) {
const normalized = ip.toLowerCase();
return (
normalized.startsWith('fc') ||
normalized.startsWith('fd') ||
normalized.startsWith('fe80')
);
}
const parts = ip.split('.');
if (parts.length !== 4) {
return false;
}
const octets = parts.map((part) => Number(part));
if (octets.some((octet) => !Number.isInteger(octet) || octet < 0 || octet > 255)) {
return false;
}
const [a, b] = octets;
if (a === 10) {
return true;
}
if (a === 172 && b >= 16 && b <= 31) {
return true;
}
if (a === 192 && b === 168) {
return true;
}
if (a === 169 && b === 254) {
return true;
}
return false;
}
function hashVisitorId(ip, userAgent) {