Skip to content
RCE Advisory Intermediate CVE-2020-24391

GHSL-2020-131: Remote Code Execution in mongo-express - CVE-2020-24391

Mongo-express uses safer-eval to validate user-supplied JavaScript, but the sandbox can be bypassed, allowing an attacker to execute arbitrary commands on the Node server. An authenticated user can be tricked into submitting a malicious form that runs code on the host.

agustingianni Follow

Originally disclosed on GitHub Security Lab

Mongo-express uses safer-eval to validate user supplied javascript. Unfortunately safer-eval sandboxing capabilities are easily bypassed leading to RCE in the context of the node server.

agustingianni, on GitHub Security Lab

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

How it worked

Root cause

The safer-eval library's sandbox can be escaped, allowing access to the Node.js process object and thus arbitrary command execution.

Impact

An attacker could execute arbitrary commands on the host, leading to remote code execution; the exploit relies on the lack of CSRF protection but an authenticated attacker could also escalate privileges.

What the attacker needed

Victim logged into mongo-express; victim visits attacker page; no CSRF protection

The fix

The issue was fixed in a commit referenced in the report.

How it was found

  1. Create an HTML file with a form that posts to the /checkValid endpoint and includes JavaScript that sets the form value to a malicious payload.
  2. Serve the HTML file from a local web server.
  3. Ensure a user is logged into mongo-express in the same browser.
  4. Visit the page, which automatically submits the form to the target.
  5. Observe the command execution in the mongo-express console.

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.

Mongo-express is a web tool for managing MongoDB databases. It tried to safely run small pieces of JavaScript sent by users, but the safety check could be tricked. This let an attacker run their own commands on the server, which is very dangerous.

What is RCE?

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

More by agustingianni

View all

24 more disclosed reports, best first.

More from GitHub Security Lab

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.