From b0e2a56b4f64978295c43f5e32c22d7bf7f499a9 Mon Sep 17 00:00:00 2001 From: Cmliakos Date: Mon, 15 Dec 2025 23:09:30 -0500 Subject: [PATCH 1/2] Remove profanity search from activities --- backend/middleware/profanity.js | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/backend/middleware/profanity.js b/backend/middleware/profanity.js index 28aecff..3ff3005 100644 --- a/backend/middleware/profanity.js +++ b/backend/middleware/profanity.js @@ -21,19 +21,47 @@ function scanValue(value) { return false; } +function removeKeys(obj, keys) { + if (!obj || typeof obj !== "object") return; + + if (Array.isArray(obj)) { + obj.forEach((v) => removeKeys(v, keys)); + return; + } + + keys.forEach((k) => { + delete obj[k]; + }); + + Object.values(obj).forEach((v) => removeKeys(v, keys)); +} + export function profanity(req, res, next) { + const skipProfanityPaths = [ + "/placesAPI/search", + "/placesAPI/cityAutocomplete", + "/activities/create", + "/activities/delete", + "/activities/update", + ]; + + const cleanUrl = req.originalUrl.split("?")[0]; + + if (skipProfanityPaths.some((p) => cleanUrl.startsWith(p))) { + return next(); + } + if (req.method === "GET" || req.method === "HEAD") return next(); if (!req.body || typeof req.body !== "object") return next(); - const ignoredKeys = ["customPhoto", "photo", "pfp"]; + const bodyToScan = structuredClone(req.body); - const filtered = Object.fromEntries( - Object.entries(req.body).filter(([key]) => !ignoredKeys.includes(key)) - ); + const ignoredKeys = ["customPhoto", "photo", "pfp"]; + removeKeys(bodyToScan, ignoredKeys); - if (scanValue(filtered)) { + if (scanValue(bodyToScan)) { return res.status(400).json({ error: "Profanity detected." }); } next(); -} \ No newline at end of file +}v \ No newline at end of file From 74fec7aae2d6d80279722109eb0d227465529820 Mon Sep 17 00:00:00 2001 From: Cmliakos Date: Mon, 15 Dec 2025 23:12:10 -0500 Subject: [PATCH 2/2] remove random letter from end of file --- backend/middleware/profanity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/middleware/profanity.js b/backend/middleware/profanity.js index 3ff3005..eda62d9 100644 --- a/backend/middleware/profanity.js +++ b/backend/middleware/profanity.js @@ -64,4 +64,4 @@ export function profanity(req, res, next) { } next(); -}v \ No newline at end of file +} \ No newline at end of file