quote the value in error message

This commit is contained in:
Girish Ramakrishnan
2025-09-08 18:59:47 +02:00
parent 8d9fe13490
commit 33c75076da
4 changed files with 6 additions and 6 deletions

View File

@@ -78,12 +78,12 @@ async function setBlocklist(blocklist, auditSource) {
for (const line of blocklist.split('\n')) {
if (!line || line.startsWith('#')) continue;
const rangeOrIP = line.trim();
if (!ipaddr.isValid(rangeOrIP) && !ipaddr.isValidCIDR(rangeOrIP)) throw new BoxError(BoxError.BAD_FIELD, `${rangeOrIP} is not a valid IP or range`);
if (!ipaddr.isValid(rangeOrIP) && !ipaddr.isValidCIDR(rangeOrIP)) throw new BoxError(BoxError.BAD_FIELD, `'${rangeOrIP}' is not a valid IP or range`);
if (rangeOrIP.indexOf('/') === -1) {
if (ipaddr.isEqual(rangeOrIP, auditSource.ip)) throw new BoxError(BoxError.BAD_FIELD, `IP ${rangeOrIP} is the client IP. Cannot block yourself`);
if (ipaddr.isEqual(rangeOrIP, auditSource.ip)) throw new BoxError(BoxError.BAD_FIELD, `IP '${rangeOrIP}' is the client IP. Cannot block yourself`);
} else {
if (ipaddr.includes(rangeOrIP, auditSource.ip)) throw new BoxError(BoxError.BAD_FIELD, `range ${rangeOrIP} includes client IP. Cannot block yourself`);
if (ipaddr.includes(rangeOrIP, auditSource.ip)) throw new BoxError(BoxError.BAD_FIELD, `range '${rangeOrIP}' includes client IP. Cannot block yourself`);
}
// this won't work in cases where it's a bigger subnet