Add IP validation

This commit is contained in:
Malachi Soord 2023-11-11 11:32:41 +01:00
parent 8160930470
commit ad71fc9481
No known key found for this signature in database
GPG key ID: C61BEBD6CC542333

View file

@ -123,6 +123,15 @@ if (ipsToAllow !== undefined) {
log.error("server", "IPs to allow must be a string, " + typeof ipsToAllow + " provided");
process.exit(1);
}
const net = require("net");
for (const ip of ipsToAllow.split(",")) {
if (net.isIP(ip) === 0) {
log.error("server", "Provided IPs to allow must be valid IP addresses, " + ip + " provided");
process.exit(1);
}
}
log.info("server", "IPs to allow: " + ipsToAllow);
const ipfilter = require("express-ipfilter").IpFilter;
app.use(ipfilter(ipsToAllow.split(","), { mode: "allow" }));