Mongooseに認証を回避される脆弱性、接続単位のsanitizeFilterが効かない
Summary
Mongooseの接続単位のsanitizeFilter設定が、クエリの絞り込み条件に適用されない脆弱性です。攻撃者が問い合わせ条件に演算子を含む値を入れると、正しいパスワードを知らなくてもアカウントに一致させられるおそれがあります。影響は6.0.0から6.13.12、7.8.13、8.24.7、9.11.4より前のバージョンで、6.13.12、7.8.13、8.24.7、9.11.4で修正されています。
AI summary
Produced by SecPulse using an external AI model; it may contain mistakes. Check the original description and references below before acting on it.
Mongooseの接続単位のsanitizeFilter設定が、クエリの絞り込み条件に適用されない脆弱性です。攻撃者が問い合わせ条件に演算子を含む値を入れると、正しいパスワードを知らなくてもアカウントに一致させられるおそれがあります。影響は6.0.0から6.13.12、7.8.13、8.24.7、9.11.4より前のバージョンで、6.13.12、7.8.13、8.24.7、9.11.4で修正されています。
Affected packages
| Package | Affected → Fixed | |
|---|---|---|
| Automatticmongoose | — | Not listed |
| npmmongoose |
≥ 9.0.0, < 9.11.4→ 9.11.4 |
9.11.4 |
| Bitnamimongoose |
≥ 6.0.0, < 6.13.12→ 6.13.12 ≥ 7.0.0, < 7.8.13→ 7.8.13 ≥ 8.0.0, < 8.24.7→ 8.24.7 ≥ 9.0.0, < 9.11.4→ 9.11.4 |
6.13.12 7.8.13 8.24.7 9.11.4 |
Original description The description as published by the source.
Summary
sanitizeFilter exists to stop query selector injection: it wraps operator objects such as { $ne: null } in filter values in $eq, so they are matched literally. Set on a connection with mongoose.connect() or createConnection(uri, { sanitizeFilter: true }), the connection reports it as enabled but queries never apply it. An application that relies on the connection-level option and passes an attacker-controlled object into a filter therefore remains open to selector injection, and a password value of { $ne: null } returns the account record without the password.
Details
NativeConnection#createClient() at lib/drivers/node-mongodb-native/connection.js:270-272 moves options.sanitizeFilter into Connection.config and deletes the original option. Query#_castConditions() at lib/query.js:2413-2423 checks Connection.options, the global options, and the per-query options, but never Connection.config. The defense therefore does not run even though Connection#get('sanitizeFilter') returns true. This storage was introduced in Mongoose 6.0.0 and the same mismatch is present in 9.11.2.
Proof of concept
import mongoose from 'mongoose'
const conn = await mongoose.createConnection('', { sanitizeFilter: true }).asPromise()
const User = conn.model('User', new mongoose.Schema({
username: String,
password: String,
marker: String
}))
await User.create({
username: 'victim',
password: 'correct-password',
marker: 'PROTECT…
Source: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory
References
- advisory github.com
- advisory nvd.nist.gov
- package github.com
- web github.com
- web github.com
- web github.com
- web github.com
- web github.com
- web github.com
- web github.com
- web github.com
- web github.com
- web github.com