Skip to content
SQL injection Write-up Advanced

NoSQL Injections in Rocket.Chat 3.12.1: How A Small Leak Grounds A Rocket

Two NoSQL injection flaws in Rocket.Chat allowed an attacker to leak password reset tokens and any user field, then escalate to admin and remote code execution. The first needed only a known email address of a user without 2FA; the second required authentication but could leak an admin's password hash and 2FA secret.

Paul Gerste Follow

Published on sonarsource.com

Rocket.Chat is one of the most popular open source solutions for team communication, written in JavaScript and TypeScript. It has more than 12 million users worldwide and there are over 800,000 server instances deployed that are being used to exchange confidential information and files.

Paul Gerste, on sonarsource.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.

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

How it worked

Root cause

User-controlled JSON input was passed directly into MongoDB query methods without type checks or strict allowlisting, so attackers could inject query operators.

Impact

An attacker could take over accounts, escalate to admin, steal confidential data and chat messages, and execute arbitrary system commands on the server; the first flaw required knowing an email of a user without 2FA, and the second required authentication.

What the attacker needed

Known email of a user without 2FA; or an authenticated account; network access to the Rocket.Chat instance

The fix

The vulnerabilities were fixed in version 3.13.2 and backported to 3.12.4 and 3.11.4 by adding type checks and stricter validation of query operators.

How it was found

  1. Request a password reset for a user whose email address is known and who has 2FA disabled.
  2. Call the unauthenticated password policy method with a crafted query object that uses a regex operator to test guesses about the reset token.
  3. Observe whether the response returns the password policy or an error to learn each character of the token.
  4. Use the leaked token to set a new password and log in as that user.
  5. With an authenticated session, query the users list endpoint using a top-level operator that throws an error containing a chosen field value.
  6. Leak an admin's email, password hash and 2FA secret, reset the password, log in, then use the integrations feature to run a script that escapes the Node.js VM and executes system commands.

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 write-up has not been written yet. The Original tab links to the source.

Rocket.Chat stores its data in MongoDB, a database that accepts queries written as JSON-like objects. If a program lets a user supply an object where it expected a plain string, the user can sneak in special query instructions that change what the database returns. Here that let an attacker guess secret tokens character by character and read private fields such as password hashes.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

More by Paul Gerste

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.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.