diff --git a/server/server.js b/server/server.js index d2af1cf41..d36ca662e 100644 --- a/server/server.js +++ b/server/server.js @@ -641,6 +641,10 @@ let needSetup = false; let notificationIDList = monitor.notificationIDList; delete monitor.notificationIDList; + // Ensure status code ranges are strings + if (!monitor.accepted_statuscodes.every((code) => typeof code === "string")) { + throw new Error("Accepted status codes are not all strings"); + } monitor.accepted_statuscodes_json = JSON.stringify(monitor.accepted_statuscodes); delete monitor.accepted_statuscodes; @@ -706,6 +710,11 @@ let needSetup = false; removeGroupChildren = true; } + // Ensure status code ranges are strings + if (!monitor.accepted_statuscodes.every((code) => typeof code === "string")) { + throw new Error("Accepted status codes are not all strings"); + } + bean.name = monitor.name; bean.description = monitor.description; bean.parent = monitor.parent; diff --git a/server/util-server.js b/server/util-server.js index 985fddb63..8354b5609 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -720,7 +720,6 @@ exports.checkCertificate = function (res) { * @param {number} status The status code to check * @param {string[]} acceptedCodes An array of accepted status codes * @returns {boolean} True if status code within range, false otherwise - * @throws {Error} Will throw an error if the provided status code is not a valid range string or code string */ exports.checkStatusCode = function (status, acceptedCodes) { if (acceptedCodes == null || acceptedCodes.length === 0) { @@ -728,6 +727,11 @@ exports.checkStatusCode = function (status, acceptedCodes) { } for (const codeRange of acceptedCodes) { + if (typeof codeRange !== "string") { + log.error("monitor", `Accepted status code not a string. ${codeRange} is of type ${typeof codeRange}`); + continue; + } + const codeRangeSplit = codeRange.split("-").map(string => parseInt(string)); if (codeRangeSplit.length === 1) { if (status === codeRangeSplit[0]) { @@ -738,7 +742,8 @@ exports.checkStatusCode = function (status, acceptedCodes) { return true; } } else { - throw new Error("Invalid status code range"); + log.error("monitor", `${codeRange} is not a valid status code range`); + continue; } }