From 28f329e3158f293dd11e11b8b6d6debe80883549 Mon Sep 17 00:00:00 2001 From: Bill Church Date: Sat, 17 Aug 2024 14:20:01 +0000 Subject: [PATCH] feat: validateSshTerm checks if term is undefined or null before validation --- app/utils.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/utils.js b/app/utils.js index e4f6ad3..ad7a98e 100644 --- a/app/utils.js +++ b/app/utils.js @@ -1,6 +1,8 @@ // server // /app/utils.js -const validator = require("validator"); +const validator = require("validator") +const createDebug = require("debug") +const debug = createDebug("webssh2:utils") /** * Sanitizes an object by replacing sensitive properties with asterisks. @@ -34,7 +36,6 @@ function sanitizeObject( return obj } - /** * Validates the SSH terminal name using validator functions. * Allows alphanumeric characters, hyphens, and periods. @@ -42,6 +43,11 @@ function sanitizeObject( * @returns {boolean} True if the terminal name is valid, false otherwise */ function validateSshTerm(term) { + debug(`validateSshTerm: %O`, term) + + if (term === undefined || term === null) { + return false + } return ( validator.isLength(term, { min: 1, max: 30 }) && validator.matches(term, /^[a-zA-Z0-9.-]+$/) @@ -49,4 +55,4 @@ function validateSshTerm(term) { } exports.sanitizeObject = sanitizeObject -exports.validateSshTerm = validateSshTerm; +exports.validateSshTerm = validateSshTerm