fix: disable ip-cidr on empty cidr list

This commit is contained in:
Ben Allfree 2024-02-29 02:46:04 -08:00
parent 771fb00d62
commit cae8e79e0f

View File

@ -11,7 +11,10 @@ export const createIpWhitelistMiddleware = (blockedCIDRs: string[]) => {
next: express.NextFunction,
) => {
const ip = req.ip // or req.headers['x-forwarded-for'] || req.connection.remoteAddress;
if (blockedCIDRObjects.some((cidr) => cidr.contains(ip))) {
if (
blockedCIDRs.length === 0 ||
blockedCIDRObjects.some((cidr) => cidr.contains(ip))
) {
next()
} else {
res.status(403).send('Nope')