Skip to content

Node.js based forum software built for the modern web

fix: tx.escape user.displayname when merging notifs

Barış Soner Uşaklı420b8238daff
diff --git a/src/notifications.js b/src/notifications.js
index f551bea8c4..53f0c3ad62 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -527,16 +527,6 @@ Notifications.merge = async function (notifications) {
}, []);
differentiators.forEach((differentiator) => {
- function typeFromLength(items) {
- if (items.length <= 1) {
- return '';
- } else if (items.length === 2) {
- return 'dual';
- } else if (items.length === 3) {
- return 'triple';
- }
- return 'multiple';
- }
let set;
if (differentiator === 0 && differentiators.length === 1) {
set = isolated;
@@ -554,25 +544,15 @@ Notifications.merge = async function (notifications) {
const { roomId, roomName, type, user } = set[0];
const isGroupChat = type === 'new-group-chat';
notifObj.bodyShort = isGroupChat || (roomName !== `[[modules:chat.room-id, ${roomId}]]`) ?
- tx.compile('notifications:new-messages-in', set.length, roomName) :
- tx.compile('notifications:new-messages-from', set.length, user.displayname);
+ tx.compile('notifications:new-messages-in', set.length, tx.escape(roomName)) :
+ tx.compile('notifications:new-messages-from', set.length, tx.escape(user.displayname));
break;
}
case 'notifications:user-posted-in-public-room': {
- const usernames = _.uniq(set.map(n => n?.user?.displayname)).filter(Boolean);
- const type = typeFromLength(usernames);
- const isMultiple = type === 'multiple';
- const txArgs = [
- `${mergeId}${type ? `-${type}` : ''}`,
- ...usernames.slice(0, usernames.length <= 3 ? 3 : 2),
- ...(isMultiple ? [usernames.length - 2] : []),
- notifObj.roomIcon,
- notifObj.roomName,
- ];
-
- notifObj.bodyShort = tx.compile(...txArgs);
- notifObj.path = set[set.length - 1].path;
+ buildMergedNotif(mergeId, notifObj, set, [
+ notifObj.roomIcon, tx.escape(notifObj.roomName),
+ ]);
break;
}
case 'notifications:upvoted-your-post-in':
@@ -581,17 +561,9 @@ Notifications.merge = async function (notifications) {
case 'notifications:user-flagged-post-in':
case 'notifications:user-flagged-user':
case 'notifications:activitypub.announce': {
- const usernames = _.uniq(set.map(n => n?.user?.displayname)).filter(Boolean);
- const type = typeFromLength(usernames);
- const isMultiple = type === 'multiple';
- const txArgs = [
- `${mergeId}${type ? `-${type}` : ''}`,
- ...usernames.slice(0, usernames.length <= 3 ? 3 : 2),
- ...(isMultiple ? [usernames.length - 2] : []),
- utils.decodeHTMLEntities(notifObj.topicTitle || ''),
- ];
- notifObj.bodyShort = tx.compile(...txArgs);
- notifObj.path = set[set.length - 1].path;
+ buildMergedNotif(mergeId, notifObj, set, [
+ tx.escape(notifObj.topicTitle),
+ ]);
break;
}
@@ -619,4 +591,29 @@ Notifications.merge = async function (notifications) {
return data && data.notifications;
};
+function buildMergedNotif(mergeId, notifObj, notifObjsToMerge, args) {
+ const usernames = _.uniq(notifObjsToMerge.map(n => tx.escape(n?.user?.displayname))).filter(Boolean);
+ const type = typeFromLength(usernames);
+ const isMultiple = type === 'multiple';
+ const txArgs = [
+ `${mergeId}${type ? `-${type}` : ''}`,
+ ...usernames.slice(0, usernames.length <= 3 ? 3 : 2),
+ ...(isMultiple ? [usernames.length - 2] : []),
+ ...args,
+ ];
+ notifObj.bodyShort = tx.compile(...txArgs);
+ notifObj.path = notifObjsToMerge[notifObjsToMerge.length - 1].path;
+}
+
+function typeFromLength(items) {
+ if (items.length <= 1) {
+ return '';
+ } else if (items.length === 2) {
+ return 'dual';
+ } else if (items.length === 3) {
+ return 'triple';
+ }
+ return 'multiple';
+}
+
require('./promisify')(Notifications);