CVE-2026-42334: Mongoose's Improper Sanitization of $nor in sanitizeFilter May Allow NoSQL Injection
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.
Published May 5, 2026 · Updated May 14, 2026
Affected packages
mongoose
- Ecosystem
- npm
- Affected
- < 6.13.9
- Fixed in
- 6.13.9
- Check
npm ls mongoose
mongoose
- Ecosystem
- npm
- Affected
- >= 7.0.0, <= 7.8.8
- Fixed in
- 7.8.9
- Check
npm ls mongoose
mongoose
- Ecosystem
- npm
- Affected
- >= 8.0.0, <= 8.22.0
- Fixed in
- 8.22.1
- Check
npm ls mongoose
mongoose
- Ecosystem
- npm
- Affected
- >= 9.0.0, <= 9.1.5
- Fixed in
- 9.1.6
- Check
npm ls mongoose
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
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 onsanitizeFilterto 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
Credited to cataliniovita-snyk, katzj.
References
- https://github.com/Automattic/mongoose/security/advisories/GHSA-wpg9-53fq-2r8h
- https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.sanitizeFilter()
- https://thecodebarbarian.com/whats-new-in-mongoose-6-sanitizefilter.html
- https://nvd.nist.gov/vuln/detail/CVE-2026-42334
- https://github.com/advisories/GHSA-wpg9-53fq-2r8h
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More npm vulnerabilities
All npm entriesCVE-2026-125116
Mongoose: Discriminator key values matching inherited properties (e.g. __t: 'constructor') bypass schema casting and can poison collections
medium4.8Nov 10, 2026CVE-2026-125117
Mongoose walks into inherited properties when hydrating, setting, and merging, allowing overwrites of built-in functions (denial of service) and shared schema state
high8.2Nov 10, 2026CVE-2026-125118
Mongoose: Prototype pollution via Schema.prototype.virtual()
medium6.5Nov 10, 2026CVE-2026-125119
Mongoose: Connection-level sanitizeFilter not applied
high7.5Nov 10, 2026CVE-2026-125120
Mongoose: sanitizeFilter not applied on countDocuments
critical9.8Nov 10, 2026CVE-2026-73562
Mongoose: Prototype pollution in mongoose update casting via __proto__-prefixed dotted path (Schema._getSchema/path getter)
medium6.5Jul 24, 2026
