From ff3f3012e0dfd3c76d19f881b426f9f1966782c4 Mon Sep 17 00:00:00 2001 From: Kevin <70767149+kschmelter13@users.noreply.github.com> Date: Sat, 16 Dec 2023 12:57:44 -0500 Subject: [PATCH] no special characters when creating organization Checks the organizations name for special chars using a regex --- backend/models/organization.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/models/organization.js b/backend/models/organization.js index 5b1b651f..48a528fb 100644 --- a/backend/models/organization.js +++ b/backend/models/organization.js @@ -18,6 +18,16 @@ const Organization = { }; var slug = slugify(orgName, { lower: true }); + const validNameRegex = /^[a-zA-Z0-9]+$/; + + // Validate orgName against the regular expression + if (!validNameRegex.test(orgName)) { + return { + organization: null, + message: "Organization name contains invalid characters. Only alphanumeric characters are allowed.", + }; + } + const existingBySlug = await this.get({ slug }); if (!!existingBySlug) { const slugSeed = Math.floor(10000000 + Math.random() * 90000000);