summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorroot <root@nomchy-verse.com>2025-03-25 16:02:47 -0700
committerroot <root@nomchy-verse.com>2025-03-25 16:02:47 -0700
commitd8b1a8484c6853c4d909046d8a8f8bd2c4afd6a1 (patch)
treeff9e68e80c367082a40e9e3bfa5591bfa1d5001c /src/api
parentModified Flake.lock to not fail the check (diff)
downloadserver-ts-d8b1a8484c6853c4d909046d8a8f8bd2c4afd6a1.tar.xz
Validate Name for webhooks enforced more
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/webhooks.ts33
-rw-r--r--src/api/routes/webhooks/#webhook_id/#token/index.ts32
2 files changed, 3 insertions, 62 deletions
diff --git a/src/api/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts

index 152f6d00..0df53a86 100644 --- a/src/api/routes/channels/#channel_id/webhooks.ts +++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -29,6 +29,7 @@ import { isTextChannel, trimSpecial, FieldErrors, + ValidateName, } from "@spacebar/util"; import crypto from "crypto"; import { Request, Response, Router } from "express"; @@ -113,37 +114,7 @@ router.post( // TODO: move this if (name) { - const check_username = name.replace(/\s/g, ""); - if (!check_username) { - throw FieldErrors({ - username: { - code: "BASE_TYPE_REQUIRED", - message: req.t("common:field.BASE_TYPE_REQUIRED"), - }, - }); - } - - const { maxUsername } = Config.get().limits.user; - if ( - check_username.length > maxUsername || - check_username.length < 2 - ) { - throw FieldErrors({ - username: { - code: "BASE_TYPE_BAD_LENGTH", - message: `Must be between 2 and ${maxUsername} in length.`, - }, - }); - } - - const blockedContains = ["discord", "clyde", "spacebar"]; - for (const word of blockedContains) { - if (name.toLowerCase().includes(word)) { - return res.status(400).json({ - username: [`Username cannot contain "${word}"`], - }); - } - } + ValidateName(name); } if (avatar) avatar = await handleFile(`/avatars/${channel_id}`, avatar); diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#token/index.ts
index aea9ba87..0de43af3 100644 --- a/src/api/routes/webhooks/#webhook_id/#token/index.ts +++ b/src/api/routes/webhooks/#webhook_id/#token/index.ts
@@ -134,37 +134,7 @@ router.post( // block username from containing certain words // TODO: configurable additions if (body.username) { - const check_username = body.username.replace(/\s/g, ""); - if (!check_username) { - throw FieldErrors({ - username: { - code: "BASE_TYPE_REQUIRED", - message: req.t("common:field.BASE_TYPE_REQUIRED"), - }, - }); - } - - const { maxUsername } = Config.get().limits.user; - if ( - check_username.length > maxUsername || - check_username.length < 2 - ) { - throw FieldErrors({ - username: { - code: "BASE_TYPE_BAD_LENGTH", - message: `Must be between 2 and ${maxUsername} in length.`, - }, - }); - } - - const blockedContains = ["discord", "clyde", "spacebar"]; - for (const word of blockedContains) { - if (body.username.toLowerCase().includes(word)) { - return res.status(400).json({ - username: [`Username cannot contain "${word}"`], - }); - } - } + ValidateName(body.username); } // block username from being certain words