userdirectory: move the validation and apply logic

This commit is contained in:
Girish Ramakrishnan
2022-02-16 12:57:38 -08:00
parent 2ed770affd
commit 426ed435a4
3 changed files with 48 additions and 31 deletions
+1
View File
@@ -30,6 +30,7 @@ async function setBlocklist(blocklist, auditSource) {
for (const line of blocklist.split('\n')) {
if (!line || line.startsWith('#')) continue;
const rangeOrIP = line.trim();
// this checks for IPv4 and IPv6
if (!validator.isIP(rangeOrIP) && !validator.isIPRange(rangeOrIP)) throw new BoxError(BoxError.BAD_FIELD, `${rangeOrIP} is not a valid IP or range`);
if (rangeOrIP.indexOf('/') === -1) {