Skip to content
Info disclosure Disclosed report Intermediate

[express-cart] Customer and admin email enumeration through MongoDB injection

The login handlers for both customers and administrators passed JSON body parameters directly into MongoDB queries without sanitisation, allowing an attacker to inject operators such as $regex. This enabled blind enumeration of all customer and administrator email addresses stored in the database.

Benoit Côté-Jodoin Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Triaged in 36 hours
  • Fixed in 21 days
  • Disclosed after 21 days

I would like to report an injection in express-cart It allows to enumerate the email address of the customers and the administrators.

Module

module name: express-cart version: 1.1.7 npm page: https://www.npmjs.com/package/express-cart

Module Description

expressCart is a fully functional shopping cart built in Node.js (Express, MongoDB) with Stripe, PayPal and Authorize.net payments.

Module Stats

31 downloads in the last week

Vulnerability

Vulnerability Description

The vulnerability is caused by the lack of user input sanitization in the login handlers. In both cases, the customer login and the admin login, parameters from the JSON body are sent directly into the MongoDB query which allows to insert operators. These operators can be used to extract the value of the field blindly in the same manner of a blind SQL injection. In this case, the $regex operator is used to guess each character of the token from the start.

Steps To Reproduce:

Use MongoDB $regex operator to test if each characters of the emails in the database.

The provided Python script exploits the customer login to find all the customer emails in the database. Some recursion is used to make sure all of the fields

The attached screenshot is the customer list currently in my database. The output of the script is the following:

$ python exploit.py 
[email protected]
[email protected]
[email protected]
[email protected]

Patch

Ensure the parameters are indeed strings before doing a MongoDB request. There are multiple ways this could be achieved. Using toString on the parameters is good enough.

db.customers.findOne({email: req.body.loginEmail}, (err, customer) => { // eslint-disable-line

becomes

db.customers.findOne({email: req.body.loginEmail.toString()}, (err, customer) => { // eslint-disable-line

While a user can still trigger an exception by replacing toString with something else than a function, it effectively mitigates the vulnerability.

Supporting Material/References:

  • OS: Ubuntu 16.04.3 LTS
  • Node.js version: 8.11.1
  • For the script: Python 2.7.12 and the requests package

Wrap up

  • I contacted the maintainer to let them know: No
  • I opened an issue in the related repository: No

Impact

Administrator emails could be used for phishing attemps and spam. Customers emails could be used by an adversary to deliver spam, steal customers and more. In this GDPR era, leaking customer emails is not very desirable.

Attachments

expressCart-admin-emails.png
expressCart-admin-emails.png From the original on HackerOne

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

Root cause

Likely the login handlers did not verify that the email parameter was a string before using it in a MongoDB query, so an attacker could supply a query operator object instead of a plain string.

Impact

An attacker could enumerate all customer and administrator email addresses, which could then be used for spam, phishing, or stealing customers.

What the attacker needed

Access to the login endpoint; no authentication required

The fix

The login handlers should ensure the email parameter is a string before using it in a MongoDB query, for example by calling toString on it.

How it was found

  1. Send a login request with a MongoDB $regex operator in the email field to test whether a guessed character matches any email.
  2. Use recursion to extend the guess character by character until a full email is found.
  3. Repeat the process to enumerate all customer emails in the database.

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 log in, the app takes your email and password and looks them up in a database. Here, the app did not check that the email was actually text; it let the user send a special database instruction instead. By sending many such instructions, an attacker could ask the database yes/no questions and slowly guess every email address stored in it.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Benoit Côté-Jodoin

View all

1 more disclosed report, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.