Packages / mongoose / Security
Mongoose: sanitizeFilter not applied on countDocuments
Affected releases · mongoose
- 9.x9.0.0 – 9.9.1Fixed in 9.9.2
- 8.x8.0.0 – 8.24.2Fixed in 8.24.3
- 7.x7.0.0 – 7.8.11Fixed in 7.8.12
- 6.x6.0.0 – 6.13.10Fixed in 6.13.11
- 5.x and older0.0.1 – 5.13.23No fix, no longer updated
On 9.x, the newest line:
npm install mongoose@9.9.2Every release on a timeline
Affected
9.0.0 – 9.9.1
35 releases
Fixed
9.9.2 – 9.12.3
18 releases
Affected
8.0.0 – 8.24.2
104 releases
Fixed
8.24.3 – 8.24.10
8 releases
Affected
7.0.0 – 7.8.11
57 releases
Fixed
7.8.12 – 7.8.14
3 releases
Affected
6.0.0 – 6.13.10
120 releases
Fixed
6.13.11 – 6.13.13
3 releases
Affected
5.0.0 – 5.13.23
255 releases
Affected
4.0.0 – 4.13.21
164 releases
Affected
3.0.0 – 3.9.7
104 releases
Affected
2.0.0 – 2.9.10
84 releases
Affected
1.0.0 – 1.8.4
64 releases
Affected
0.0.1 – 0.0.6
6 releases
What happens
Impact
sanitizeFilter is Mongoose's mechanism for protecting against query selector injection attacks. In older versions of Mongoose, sanitizeFilter was not applied for countDocuments() queries.
Patches
Patches have been released for all supported Mongoose major release lines. Please upgrade to the following versions depending on which major version of Mongoose applications are using.
^9.9.2^8.24.3^7.8.12^6.13.11
Workarounds
Middleware:
mongoose.plugin(function() {
schema.pre('countDocuments', function() {
// This will always apply `sanitizeFilter` on `countDocuments`
mongoose.sanitizeFilter(this.getFilter());
});
});A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.