Skip to content

Commit

Permalink
fix: do not blindly escape a notification's bodyLong
Browse files Browse the repository at this point in the history
For 7+ years we were escaping this value, but it is in many cases already sanitized (as it may be a post content). For those cases when it is not, I now run it through parse.raw.

Instead of escaping, it now strips p, img, and a tags.
  • Loading branch information
julianlam committed Feb 9, 2021
1 parent 0092df2 commit 783786c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Flags.notify = async function (flagObj, uid) {
notifObj = await notifications.create({
type: 'new-post-flag',
bodyShort: `[[notifications:user_flagged_post_in, ${flagObj.reports[flagObj.reports.length - 1].reporter.username}, ${titleEscaped}]]`,
bodyLong: flagObj.description,
bodyLong: await plugins.hooks.fire('filter:parse.raw', flagObj.description),
pid: flagObj.targetId,
path: `/flags/${flagObj.flagId}`,
nid: `flag:post:${flagObj.targetId}`,
Expand All @@ -733,7 +733,7 @@ Flags.notify = async function (flagObj, uid) {
notifObj = await notifications.create({
type: 'new-user-flag',
bodyShort: `[[notifications:user_flagged_user, ${flagObj.reports[flagObj.reports.length - 1].reporter.username}, ${flagObj.target.username}]]`,
bodyLong: flagObj.description,
bodyLong: await plugins.hooks.fire('filter:parse.raw', flagObj.description),
path: `/flags/${flagObj.flagId}`,
nid: `flag:user:${flagObj.targetId}`,
from: uid,
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function (Messaging) {
type: isGroupChat ? 'new-group-chat' : 'new-chat',
subject: `[[email:notif.chat.subject, ${messageObj.fromUser.username}]]`,
bodyShort: `[[notifications:new_message_from, ${messageObj.fromUser.username}]]`,
bodyLong: messageObj.content,
bodyLong: await plugins.hooks.fire('filter:parse.raw', messageObj.content),
nid: `chat_${fromuid}_${roomId}`,
from: fromuid,
path: `/chats/${messageObj.roomId}`,
Expand Down
2 changes: 1 addition & 1 deletion src/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Notifications.getMultiple = async function (nids) {
notification.datetimeISO = utils.toISOString(notification.datetime);

if (notification.bodyLong) {
notification.bodyLong = utils.escapeHTML(notification.bodyLong);
notification.bodyLong = utils.stripHTMLTags(notification.bodyLong, ['img', 'p', 'a']);
}

notification.user = usersData[index];
Expand Down
2 changes: 1 addition & 1 deletion src/posts/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = function (Posts) {
nid: `post-queue-${id}`,
mergeId: 'post-queue',
bodyShort: '[[notifications:post_awaiting_review]]',
bodyLong: data.content,
bodyLong: await plugins.hooks.fire('filter:parse.raw', data.content),
path: '/post-queue',
});
await notifications.push(notifObj, uids);
Expand Down

0 comments on commit 783786c

Please sign in to comment.