Last tested: 20 Feb, 2018

mongoose vulnerabilities

Mongoose MongoDB ODM

View on npm

mongoose (latest)

Published 19 Feb, 2018

Known vulnerabilities0
Vulnerable paths0
Dependencies19

No known vulnerabilities in mongoose

Security wise, mongoose seems to be a safe package to use.
Over time, new vulnerabilities may be disclosed on mongoose and other packages. To easily find, fix and prevent such vulnerabilties, protect your repos with Snyk!

Vulnerable versions of mongoose

Fixed in 4.11.14

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: mongoose@4.11.13 > mquery@2.3.1 > debug@2.6.8

Overview

debug is a JavaScript debugging utility modelled after Node.js core's debugging technique..

debug uses printf-style formatting. Affected versions of this package are vulnerable to Regular expression Denial of Service (ReDoS) attacks via the the %o formatter (Pretty-print an Object all on a single line). It used a regular expression (/\s*\n\s*/g) in order to strip whitespaces and replace newlines with spaces, in order to join the data into a single line. This can cause a very low impact of about 2 seconds matching time for data 50k characters long.

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

You can read more about Regular Expression Denial of Service (ReDoS) on our blog.

Remediation

Upgrade debug to version 2.6.9, 3.1.0 or higher.

References

Fixed in 4.10.2

Regular Expression Denial of Service (ReDoS)

low severity

Detailed paths

  • Introduced through: express@4.10.1 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@4.10.1 > finalhandler@0.3.2 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@4.10.1 > send@0.10.1 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@4.10.1 > serve-static@1.7.2 > send@0.10.1 > debug@2.1.3 > ms@0.7.0
  • Introduced through: express@4.10.1 > send@0.10.1 > ms@0.6.2
  • Introduced through: express@4.10.1 > serve-static@1.7.2 > send@0.10.1 > ms@0.6.2
  • Introduced through: mongoose@4.10.1 > ms@0.7.2
  • Introduced through: mongoose@4.10.1 > mquery@2.3.0 > debug@2.2.0 > ms@0.7.1

Overview

ms is a tiny millisecond conversion utility.

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to an incomplete fix for previously reported vulnerability npm:ms:20151024. The fix limited the length of accepted input string to 10,000 characters, and turned to be insufficient making it possible to block the event loop for 0.3 seconds (on a typical laptop) with a specially crafted string passed to ms() function.

Proof of concept

ms = require('ms');
ms('1'.repeat(9998) + 'Q') // Takes about ~0.3s

Note: Snyk's patch for this vulnerability limits input length to 100 characters. This new limit was deemed to be a breaking change by the author. Based on user feedback, we believe the risk of breakage is very low, while the value to your security is much greater, and therefore opted to still capture this change in a patch for earlier versions as well. Whenever patching security issues, we always suggest to run tests on your code to validate that nothing has been broken.

For more information on Regular Expression Denial of Service (ReDoS) attacks, go to our blog.

Disclosure Timeline

  • Feb 9th, 2017 - Reported the issue to package owner.
  • Feb 11th, 2017 - Issue acknowledged by package owner.
  • April 12th, 2017 - Fix PR opened by Snyk Security Team.
  • May 15th, 2017 - Vulnerability published.
  • May 16th, 2017 - Issue fixed and version 2.0.0 released.
  • May 21th, 2017 - Patches released for versions >=0.7.1, <=1.0.0.

Remediation

Upgrade ms to version 2.0.0 or higher.

References

Fixed in 4.3.6

Remote Memory Exposure

medium severity

Detailed paths

  • Introduced through: mongoose@4.3.5

Overview

A potential memory disclosure vulnerability exists in mongoose. A Buffer field in a MongoDB document can be used to expose sensitive information such as code, runtime memory and user data into MongoDB.

Details

Initializing a Buffer field in a document with integer N creates a Buffer of length N with non zero-ed out memory. Example:

var x = new Buffer(100); // uninitialized Buffer of length 100
// vs
var x = new Buffer('100'); // initialized Buffer with value of '100'

Initializing a MongoDB document field in such manner will dump uninitialized memory into MongoDB. The patch wraps Buffer field initialization in mongoose by converting a number value N to array [N], initializing the Buffer with N in its binary form.

Proof of concept

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/bufftest');

// data: Buffer is not uncommon, taken straight from the docs: http://mongoosejs.com/docs/schematypes.html
mongoose.model('Item', new mongoose.Schema({id: String, data: Buffer}));

var Item = mongoose.model('Item');

var sample = new Item();
sample.id = 'item1';

// This will create an uninitialized buffer of size 100
sample.data = 100;
sample.save(function () {
    Item.findOne(function (err, result) {
        // Print out the data (exposed memory)
        console.log(result.data.toString('ascii'))
        mongoose.connection.db.dropDatabase(); // Clean up everything
        process.exit();
    });
});

Remediation

Upgrade mongoose to version >= 3.8.39 or >= 4.3.6.

If a direct dependency update is not possible, use snyk wizard to patch this vulnerability.

References

Fixed in 4.2.4

Regular Expression Denial of Service (DoS)

medium severity
  • Vulnerable module: ms
  • Introduced through: ms@0.1.0

Detailed paths

  • Introduced through: mongoose@4.2.3 > ms@0.1.0

Overview

ms is a tiny milisecond conversion utility.

Affected versions of this package are vulnerable to a Regular expression Denial of Service (ReDoS) attack when converting a time period string (i.e. "2 days", "1h") into milliseconds integer. A malicious user could pas extremely long strings to ms(), causing the server take a long time to process, subsequently blocking the event loop for that extended period.

Details

The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Many Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size), allowing an attacker to exploit this and can cause the program to enter these extreme situations by using a specially crafted input and cause the service to excessively consume CPU, resulting in a Denial of Service.

Remediation

Upgrade ms to version 0.7.1.

If direct dependency upgrade is not possible, use snyk wizard to patch this vulnerability.

References

Fixed in 4.1.10

Denial of Service (DoS) via Infinite Loop

high severity

Detailed paths

  • Introduced through: mongoose@4.1.9

Overview

mongoose is a MongoDB ODM. Affected versions of the package are vulnerable to Denial of Service (DoS) via Infinite Loop when calculating a corrupt array. An attacker can use this to his advantage to crash the servers.

Remediation

Upgrade mongoose to version 4.1.10 or higher.

References