From e3736862caf91ee0e100c56e58f3f56ab738701f Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Wed, 28 Feb 2024 19:04:12 -0500 Subject: [PATCH] posts: update post body checks and regex --- src/services/juxt-web/routes/console/messages.js | 14 +++++++++----- src/services/juxt-web/routes/console/posts.js | 13 ++++++++----- src/util.js | 2 ++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/services/juxt-web/routes/console/messages.js b/src/services/juxt-web/routes/console/messages.js index 8966fb7..a9ceb15 100644 --- a/src/services/juxt-web/routes/console/messages.js +++ b/src/services/juxt-web/routes/console/messages.js @@ -97,13 +97,17 @@ router.post('/new', async function (req, res, next) { miiFace = 'normal_face.png'; break; } - let body = req.body.body; - if (body) { - body = req.body.body.replace(/[^\p{L}\p{P}\d\n\r~$^¨←→↑↓√¦⇒⇔¤¢€£¥™©®+×÷=±∞˘˙¸˛˜°¹²³♭♪¬¯¼½¾♡♥●◆■▲▼☆★♀♂<>]/gu, ''); + const body = req.body.body; + if (body && util.INVALID_POST_BODY_REGEX.test(body)) { + // TODO - Log this error + return res.sendStatus(422); } - if (body.length > 280) { - body = body.substring(0,280); + + if (body && body.length > 280) { + // TODO - Log this error + return res.sendStatus(422); } + const document = { community_id: conversation.id, screen_name: req.user.mii.name, diff --git a/src/services/juxt-web/routes/console/posts.js b/src/services/juxt-web/routes/console/posts.js index bc8d045..a3aaf95 100644 --- a/src/services/juxt-web/routes/console/posts.js +++ b/src/services/juxt-web/routes/console/posts.js @@ -240,12 +240,15 @@ async function newPost(req, res) { miiFace = 'normal_face.png'; break; } - let body = req.body.body; - if (body) { - body = req.body.body.replace(/[^\p{L}\p{P}\d\n\r~$^¨←→↑↓√¦⇒⇔¤¢€£¥™©®+×÷=±∞˘˙¸˛˜°¹²³♭♪¬¯¼½¾♡♥●◆■▲▼☆★♀♂<>]/gu, ''); + const body = req.body.body; + if (body && util.INVALID_POST_BODY_REGEX.test(body)) { + // TODO - Log this error + return res.sendStatus(422); } - if (body.length > 280 && !req.moderator) { - body = body.substring(0, 280); + + if (body && body.length > 280) { + // TODO - Log this error + return res.sendStatus(422); } const document = { title_id: community.title_id[0], diff --git a/src/util.js b/src/util.js index a933634..7dbd1ff 100644 --- a/src/util.js +++ b/src/util.js @@ -74,6 +74,8 @@ function nameCache() { } const methods = { + // TODO - This doesn't belong here, just hacking it in. Gonna redo this whole server anyway so fuck it + INVALID_POST_BODY_REGEX: /[^\p{L}\p{P}\d\n\r$^¨←→↑↓√¦⇒⇔¤¢€£¥™©®+×÷=±∞˘˙¸˛˜°¹²³♭♪¬¯¼½¾♡♥●◆■▲▼☆★♀♂<> ]/gu, create_user: async function(pid, experience, notifications) { const pnid = await this.getUserDataFromPid(pid); if (!pnid) {