Node.js based forum software built for the modern web
fix: xss in room rename event in chat modals
Barış Soner Uşaklı55b1ea5f96a5
diff --git a/public/src/client/chats/events.js b/public/src/client/chats/events.jsindex 5441a63a63..e427c23ac7 100644--- a/public/src/client/chats/events.js+++ b/public/src/client/chats/events.js@@ -5,8 +5,7 @@ define('forum/chats/events', ['forum/chats/messages','chat','components',- 'helpers',-], function (messages, chatModule, components, helpers) {+], function (messages, chatModule, components) {const Events = {};const events = {@@ -99,13 +98,7 @@ define('forum/chats/events', [}const titleEl = $(`[component="chat/main-wrapper"][data-roomid="${data.roomId}"] [component="chat/header/title"]`);- if (titleEl.length) {- titleEl.translateHtml(- data.newName ?- `<i class="fa ${helpers.escape(ajaxify.data.icon)} text-muted"></i> ${helpers.escape(data.newName)}` :- data.chatWithMessage- );- }+ chatModule.updateRoomName(titleEl, ajaxify.data.icon, data.newName, data.chatWithMessage);}function markChatState({ roomId, state }) {diff --git a/public/src/modules/chat.js b/public/src/modules/chat.jsindex f39912635b..cd9c940810 100644--- a/public/src/modules/chat.js+++ b/public/src/modules/chat.js@@ -233,13 +233,7 @@ define('chat', [const modal = Chat.getModal(data.roomId);const titleEl = modal.find('[component="chat/room/name"]');const icon = titleEl.attr('data-icon');- if (titleEl.length) {- titleEl.html(- data.newName ?- `<i class="fa ${helpers.escape(icon)} text-muted"></i> ${helpers.escape(data.newName)}` :- data.chatWithMessage- );- }+ Chat.updateRoomName(titleEl, icon, data.newName, data.chatWithMessage);taskbar.update('chat', modal.attr('data-uuid'), {title: helpers.escape(data.newName),});@@ -248,6 +242,16 @@ define('chat', [}));};+ Chat.updateRoomName = function (titleEl, icon, newName, chatWithMessage) {+ if (titleEl.length) {+ titleEl.translateHtml(+ newName ?+ `<i class="fa ${helpers.escape(icon)} text-muted"></i> ${helpers.escape(newName)}` :+ chatWithMessage+ );+ }+ };+Chat.onUserTyping = function (data) {if (data.uid === app.user.uid || Chat.isFromBlockedUser(data.uid)) {return;diff --git a/src/messaging/index.js b/src/messaging/index.jsindex 28ca026a4c..212db2df52 100644--- a/src/messaging/index.js+++ b/src/messaging/index.js@@ -302,7 +302,7 @@ Messaging.generateUsernames = function (room, excludeUid) {if (users.length > 3) {return tx.compile('modules:chat.usernames-and-x-others',- usernames.slice(0, 2).map(tx.escape).join(', '),+ usernames.slice(0, 2).map(name => tx.escape(utils.escapeHTML(name))).join(', '),room.userCount - 2);}@@ -330,7 +330,7 @@ Messaging.generateChatWithMessage = async function (room, callerUid) {let compiled;const txArgs = [];userData.forEach((userData) =>{- txArgs.push(userData.href, tx.escape(userData.displayname));+ txArgs.push(userData.href, tx.escape(utils.escapeHTML(userData.displayname)));});if (moreThan3) {txArgs.push(room.userCount - 2);diff --git a/test/messaging.js b/test/messaging.jsindex 3f441c5c15..7a8c60bd1c 100644--- a/test/messaging.js+++ b/test/messaging.js@@ -639,6 +639,14 @@ describe('Messaging Library', () => {assert(body.includes(`Chat with <a href="${nconf.get('relative_path')}/uid/${uid}"><svg/onload=alert(document.location);</a>`));+ const result = await request.get(`${nconf.get('url')}/api/user/foo/chats/${rooms[0].roomId}`, {+ jar: mocks.users.foo.jar,+ });+ assert.strictEqual(+ result.body.chatWithMessage,+ `[[modules:chat.chat-with-usernames-1, /uid/${uid}, <svg/onload=alert(document.location);]]`+ );+meta.config.showFullnameAsDisplayName = oldValue;});