check for whitespace in gateways and phone numbers (#477)

This commit is contained in:
Sam Machin
2025-07-01 12:16:27 +01:00
committed by GitHub
parent 5421f1421f
commit 542ccfca79
2 changed files with 6 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ const preconditions = {
};
const sysError = require('../error');
const { parsePhoneNumberSid } = require('./utils');
const hasWhitespace = (str) => /\s/.test(str);
/* check for required fields when adding */
@@ -28,6 +29,7 @@ async function validateAdd(req) {
}
if (!req.body.number) throw new DbErrorBadRequest('number is required');
if (hasWhitespace(req.body.number)) throw new DbErrorBadRequest('number cannot contain whitespace');
const formattedNumber = e164(req.body.number);
req.body.number = formattedNumber;
} catch (err) {

View File

@@ -6,6 +6,7 @@ const decorate = require('./decorate');
const sysError = require('../error');
const net = require('net');
const hasWhitespace = (str) => /\s/.test(str);
const checkUserScope = async(req, voip_carrier_sid) => {
const {lookupCarrierBySid} = req.app.locals;
if (!voip_carrier_sid) {
@@ -60,6 +61,9 @@ const validate = async(req, sid) => {
throw new DbErrorBadRequest(
`netmask required to have value equal or greater than ${process.env.JAMBONZ_MIN_GATEWAY_NETMASK}`);
}
if (hasWhitespace(ipv4)) {
throw new DbErrorBadRequest('Gateway must not contain whitespace');
}
if (inbound && !net.isIPv4(ipv4)) {
throw new DbErrorBadRequest('Inbound gateway must be IPv4 address');
}