mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 07:37:11 +01:00
Support CIDR notation in IGNORE_IP, closes #544.
This commit is contained in:
parent
0cf115b2de
commit
92705815ed
3 changed files with 21 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import isbot from 'isbot';
|
||||
import ipaddr from 'ipaddr.js';
|
||||
import { savePageView, saveEvent } from 'lib/queries';
|
||||
import { useCors, useSession } from 'lib/middleware';
|
||||
import { getIpAddress } from 'lib/request';
|
||||
|
|
@ -15,8 +16,21 @@ export default async (req, res) => {
|
|||
if (process.env.IGNORE_IP) {
|
||||
const ips = process.env.IGNORE_IP.split(',').map(n => n.trim());
|
||||
const ip = getIpAddress(req);
|
||||
const blocked = ips.find(i => {
|
||||
if (i === ip) return true;
|
||||
|
||||
if (ips.includes(ip)) {
|
||||
// CIDR notation
|
||||
if (i.indexOf('/') > 0) {
|
||||
const addr = ipaddr.parse(ip);
|
||||
const range = ipaddr.parseCIDR(i);
|
||||
|
||||
if (addr.match(range)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (blocked) {
|
||||
return ok(res);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue