mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
check for whitespace in gateways and phone numbers (#477)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user