# Mongoose Buffer memory exposure in type casting

Source: https://junglewise.ai/threats/mongoose-buffer-memory-exposure-in-type-casting-6a778c19  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2020-09-01. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

Severity: low · CVSS 3.1 · Published 2020-09-01

Mongoose, a popular Node.js library for MongoDB database modeling, incorrectly handles type conversion when a number is saved to a Buffer field. This causes uninitialized memory chunks to be stored in the database, potentially exposing sensitive information such as credentials, tokens, or other secrets that happened to be in memory at the time of allocation. An attacker can retrieve this exposed data by querying the database.

Technologies: [mongoose (npm)](https://junglewise.ai/threats/technologies/mongoose). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Low severity, with a CVSS score of 3.1, published 1 September 2020.

**Which products and versions are affected?** mongoose (npm) SEMVER:introduced=3.5.5,fixed=3.8.39.

**Is there a fix for This vulnerability?** Yes. mongoose (npm): upgrade to 3.8.39 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked with local access, in a software library.

**Am I affected?** Check whether you run mongoose (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- mongoose (npm): upgrade to 3.8.39 or later

  ```sh
  npm install mongoose@3.8.39
  ```


## Technical details

The vulnerability is a sensitive information disclosure (CWE-201) in mongoose's type casting logic for Buffer fields. When attempting to cast a numeric value to a Buffer type, the library creates a new Buffer of size equal to the numeric value without initializing its contents. This uninitialized memory is then persisted to the database, making it available to any user with database read access. The vulnerability affects versions before 3.8.39 and 4.3.6. No special privileges or network access are required beyond the ability to write to a schema field—an attacker or malicious application code can trigger this by assigning a number to a Buffer field and saving the document. The fix was to properly initialize the buffer or reject invalid type conversions.

## Affected products

- Automattic mongoose 3.5.5 to 3.8.38, 4.0.0 to 4.3.5

## Timeline

- 2020-09-01: disclosed: Published via GitHub Advisory
- 2016-01: patched: Fixes released in versions 3.8.39 and 4.3.6

## References

- [https://github.com/Automattic/mongoose/issues/3764](https://github.com/Automattic/mongoose/issues/3764)
- [https://gist.github.com/ChALkeR/440bc3dfcbd9b6da75c3](https://gist.github.com/ChALkeR/440bc3dfcbd9b6da75c3)

## Related threats

- [Mongoose sanitizeFilter not applied on countDocuments](https://junglewise.ai/threats/cve-2026-125120-mongoose-sanitizefilter-not-applied-on-countdocuments)
- [Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. From 6.0.0 until 6.13.12, 7.8.13, 8.24.7, and 9.](https://junglewise.ai/threats/cve-2026-125119-mongoose-connection-level-sanitizefilter-not-applied)
- [Mongoose prototype pollution in Schema.prototype.virtual()](https://junglewise.ai/threats/cve-2026-125118-mongoose-prototype-pollution-via-schema-prototype-virtual)
- [Mongoose prototype pollution in object initialization](https://junglewise.ai/threats/cve-2026-125117-mongoose-is-a-mongodb-object-modeling-tool-designed-to-work-in)
- [Mongoose discriminator key inheritance bypass](https://junglewise.ai/threats/cve-2026-125116-mongoose-discriminator-key-values-matching-inherited-properties)
