From ad71fc94810762f01022e35abecc5ce22197f52a Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Sat, 11 Nov 2023 11:32:41 +0100 Subject: [PATCH] Add IP validation --- server/server.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/server.js b/server/server.js index 8c0af8d53..c9cc92f2c 100644 --- a/server/server.js +++ b/server/server.js @@ -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" }));