Skip to content

Commit 69405b2

Browse files
committed
Merge branch '6.x' into vkarpov15/gh-13191-2
2 parents f143485 + e9eb8ab commit 69405b2

File tree

14 files changed

+95
-28
lines changed

14 files changed

+95
-28
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
- name: Setup Deno
9797
uses: denoland/setup-deno@v1
9898
with:
99-
deno-version: v1.33.x
99+
deno-version: v1.34.x
100100
- run: deno --version
101101
- run: npm install
102102
- name: Run Deno tests

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
6.11.3 / 2023-07-11
2+
===================
3+
* fix: avoid prototype pollution on init
4+
* fix(schema): correctly handle uuids with populate() #13317 #13595
5+
6+
6.11.2 / 2023-06-08
7+
===================
8+
* fix(cursor): allow find middleware to modify query cursor options #13476 #13453 #13435
9+
110
6.11.1 / 2023-05-08
211
===================
312
* fix(query): apply schema-level paths before calculating projection for findOneAndUpdate() #13348 #13340

docs/layout.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ html(lang='en')
143143
li.pure-menu-item.sub-item
144144
a.pure-menu-link(href=`${versions.versionedPath}/docs/api/virtualtype.html`, class=outputUrl === `${versions.versionedPath}/docs/api/virtualtype.html` ? 'selected' : '') VirtualType
145145
li.pure-menu-item
146-
a.pure-menu-link(href=`${versions.versionedPath}/docs/migrating_to_7.html`, class=outputUrl === `${versions.versionedPath}/docs/migrating_to_7.html` ? 'selected' : '') Migration Guide
146+
a.pure-menu-link(href=`${versions.versionedPath}/docs/migrating_to_6.html`, class=outputUrl === `${versions.versionedPath}/docs/migrating_to_7.html` ? 'selected' : '') Migration Guide
147147
li.pure-menu-item
148148
a.pure-menu-link(href=`${versions.versionedPath}/docs/compatibility.html`, class=outputUrl === `${versions.versionedPath}/docs/compatibility.html` ? 'selected' : '') Version Compatibility
149149
li.pure-menu-item

lib/cursor/QueryCursor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function QueryCursor(query, options) {
6666
// Max out the number of documents we'll populate in parallel at 5000.
6767
this.options._populateBatchSize = Math.min(this.options.batchSize, 5000);
6868
}
69+
Object.assign(this.options, query._optionsForExec());
6970
model.collection.find(query._conditions, this.options, (err, cursor) => {
7071
if (err != null) {
7172
_this._markError(err);

lib/document.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,10 @@ function init(self, obj, doc, opts, prefix) {
740740

741741
function _init(index) {
742742
i = keys[index];
743+
// avoid prototype pollution
744+
if (i === '__proto__' || i === 'constructor') {
745+
return;
746+
}
743747
path = prefix + i;
744748
schemaType = docSchema.path(path);
745749

lib/schema/uuid.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const MongooseBuffer = require('../types/buffer');
88
const SchemaType = require('../schematype');
99
const CastError = SchemaType.CastError;
1010
const utils = require('../utils');
11-
const isBsonType = require('../helpers/isBsonType');
1211
const handleBitwiseOperator = require('./operators/bitwise');
1312

1413
const UUID_FORMAT = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;
@@ -86,7 +85,13 @@ function binaryToString(uuidBin) {
8685

8786
function SchemaUUID(key, options) {
8887
SchemaType.call(this, key, options, 'UUID');
89-
this.getters.push(binaryToString);
88+
this.getters.push(function(value) {
89+
// For populated
90+
if (value != null && value.$__ != null) {
91+
return value;
92+
}
93+
return binaryToString(value);
94+
});
9095
}
9196

9297
/**
@@ -110,7 +115,7 @@ SchemaUUID.prototype.constructor = SchemaUUID;
110115
*/
111116

112117
SchemaUUID._cast = function(value) {
113-
if (value === null) {
118+
if (value == null) {
114119
return value;
115120
}
116121

@@ -247,11 +252,8 @@ SchemaUUID.prototype.checkRequired = function checkRequired(value) {
247252
*/
248253

249254
SchemaUUID.prototype.cast = function(value, doc, init) {
250-
if (SchemaType._isRef(this, value, doc, init)) {
251-
if (isBsonType(value, 'UUID')) {
252-
return value;
253-
}
254-
255+
if (utils.isNonBuiltinObject(value) &&
256+
SchemaType._isRef(this, value, doc, init)) {
255257
return this._castRef(value, doc, init);
256258
}
257259

lib/schematype.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@ SchemaType.prototype._castRef = function _castRef(value, doc, init) {
15211521
const path = doc.$__fullPath(this.path, true);
15221522
const owner = doc.ownerDocument();
15231523
const pop = owner.$populated(path, true);
1524+
15241525
let ret = value;
15251526
if (!doc.$__.populated ||
15261527
!doc.$__.populated[path] ||

lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Module dependencies.
55
*/
66

7+
const UUID = require('bson').UUID;
78
const ms = require('ms');
89
const mpath = require('mpath');
910
const ObjectId = require('./types/objectid');
@@ -406,6 +407,7 @@ exports.isNonBuiltinObject = function isNonBuiltinObject(val) {
406407
return typeof val === 'object' &&
407408
!exports.isNativeObject(val) &&
408409
!exports.isMongooseType(val) &&
410+
!(val instanceof UUID) &&
409411
val != null;
410412
};
411413

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mongoose",
33
"description": "Mongoose MongoDB ODM",
4-
"version": "6.11.1",
4+
"version": "6.11.3",
55
"author": "Guillermo Rauch <[email protected]>",
66
"keywords": [
77
"mongodb",

test/collection.capped.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('collections: capped:', function() {
4646
capped.set('capped', { size: 1000 });
4747
const Capped = db.model('Test', capped, 'Test');
4848
await Capped.init();
49+
await Capped.createCollection();
4950
await new Promise((resolve) => setTimeout(resolve, 100));
5051

5152
const isCapped = await Capped.collection.isCapped();

0 commit comments

Comments
 (0)