GitHub Advisoryadvisory · npm
GHSA-wpg9-53fq-2r8h Mongoose's Improper Sanitization of $nor in sanitizeFilter May Allow NoSQL Injection
HIGH
Official page ↗
- Aliases
- CVE-2026-42334
- Ecosystem
- npm
- Packages
- mongoose
- Severity
- High
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
- Weaknesses
- CWE-74
- Reviewed
- 2026-05-05
Affected packages
• npm mongoose: < 6.13.9 → fixed in 6.13.9
• npm mongoose: >= 7.0.0, < 7.8.9 → fixed in 7.8.9
• npm mongoose: >= 8.0.0, < 8.22.1 → fixed in 8.22.1
• npm mongoose: >= 9.0.0, < 9.1.6 → fixed in 9.1.6
Description
Impact
This vulnerability allows bypassing Mongoose’s sanitizeFilter query sanitization mechanism via the `$nor` operator.
When sanitizeFilter is enabled, Mongoose wraps query operators in `$eq` to neutralize them. However, prior to the fix, `$nor` was not included in the set of logical operators that are recursively sanitized. Because `$nor` accepts an array (like `$and` and `$or`), and arrays do not trigger `hasDollarKeys()`, malicious operators such as `$ne`, `$gt`, or `$regex` could be injected inside a `$nor` clause without being sanitized.
This may lead to:
• Authentication bypass
• Unauthorized data access
• Data exfiltration
Affected users:
Applications that:
• Explicitly enable sanitizeFilter
• Pass unsanitized user-controlled input directly into query methods (e.g., `Model.findOne(req.body)`) and rely on `sanitizeFilter` to strip out query selectors
Applications that validate input schemas, whitelist fields, or avoid passing raw request bodies into queries are not affected. For example, `Model.findOne({ user: req.body.user, pwd: req.body.pwd })` is not affected.
Patches
Patches have been released for all supported Mongoose release lines:
• `^6.13.9`
• `^7.8.9`
• `^8.22.1`
• `^9.1.6`
Workarounds
Delete `$nor` keys, use an additional schema validation library, or write middleware to strip out `$nor` from query filters.
Resources
sanitizeFilter documentation: https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.sanitizeFilter()
Original blog post on sanitizeFilter: https://thecodebarbarian.com/whats-new-in-mongoose-6-sanitizefilter.html
Related
Alias · CVE (1)
- CVE-2026-42334 Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. vulnerability
Weakness · CWE (1)
- CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component weakness
References
- https://github.com/Automattic/mongoose/security/advisories/GHSA-wpg9-53fq-2r8h web
- https://nvd.nist.gov/vuln/detail/CVE-2026-42334 advisory
- https://github.com/Automattic/mongoose package
- https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.sanitizeFilter() web
- https://thecodebarbarian.com/whats-new-in-mongoose-6-sanitizefilter.html web