XSS in message attachment fileds.
The message attachment fields in Rocket.Chat render user-supplied HTML without sanitisation when no custom renderer is set. An attacker can send a message with a malicious attachment field to execute JavaScript in other users' browsers, including administrators, leading to cookie theft and privilege escalation.
Originally disclosed on HackerOne
- Triaged in 17 hours
- Fixed in 6 months
- Disclosed after 7 months
NOTE! Thanks for submitting a report! Please replace all the [square] sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to verify and then potentially issue a bounty, so be sure to take your time filling out the report!
Summary: There is a Cross-Site Scripting vulnerability in the message attachment fields.
Description:
If no custom renderer is set, the specializedRendering function will render any HTML provided in the value field of the attachment:
specializedRendering({ hash: { field, message } }) {
let html = '';
if (field.type && renderers[field.type]) {
html = Blaze.toHTMLWithData(Template[renderers[field.type]], { field, message });
} else {
// consider the value already formatted as html
html = field.value;
}
return `<div class="${ field.type }">${ html }</div>`;
},
Releases Affected:
- Rocket.Chat up to 3.3.3
Steps To Reproduce (from initial installation to vulnerability):
-
Get an Personal Access Token.
-
Create a channel "#cookies"
-
Invite administrators into "#cookies", e.g. by promising them yummy cookies.
-
Put the following payload in a file, calling it
cookiesplz.json:{ "channel": "#cookies", "text": "Hi, I'd like a cookie please", "attachments": [ { "text": "ohai", "fields": [ { "type": "hello from project pwner", "title": "pwn", "value": "test<img src=x onerror='alert(document.cookie);'/>", "short": false } ] } ] } -
Run the following curl request:
curl -H "X-Auth-Token: <Token>" -H "X-User-Id: <user Id>" -H "Content-type:application/json" https://<server>/api/v1/chat.postMessage -d @cookiesplz.json
Supporting Material/References:
Suggested mitigation
- Don't render verbatim HTML from user input.
- Mitigate XSS using CSP headers.
Impact
Using this vulnerability, an attacker can steal cookies of other users, including administrators to elevate their privileges. They can leak a user’s messages, critically impacting confidentiality. An attack payload may also Exit or delete messages, potentially removing traces of exploits and critically impacting integrity and availability. Finally, by escalating privileges, an attacker can restart the server and edit important settings, impacting availability. By using XSS execution, an attacker may send the payload to other users, i.e. this vulnerability is "wormable" on the same server.
In the electron client, this XSS can be used to get remote code execution.
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
The application renders user-controlled HTML from attachment field values without sanitisation or escaping.
Impact
An attacker could steal cookies of other users, including administrators, escalate privileges, leak messages, delete messages, restart the server, edit settings, and the XSS is wormable; in the Electron client it could lead to remote code execution.
What the attacker needed
A Personal Access Token; Ability to create a channel; Victim views the malicious message
The fix
The application should not render verbatim HTML from user input and should mitigate XSS using CSP headers.
How it was found
- Obtain a Personal Access Token.
- Create a channel named '#cookies'.
- Invite administrators to the channel.
- Craft a JSON file with a message containing an attachment field whose value includes an XSS payload.
- Send the message using a curl request to the chat.postMessage API endpoint with the token and user ID headers.
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.
When you send a message with an attachment in Rocket.Chat, the attachment can have extra fields. The server takes whatever is in the 'value' of those fields and puts it directly into the web page without cleaning it. This means an attacker can put a small script in that field, and when other people view the message, their browsers run the script, letting the attacker steal their login cookies or do things as them.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.