Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Fix #14567

Summary

Currently, when you call TestModel.find({ $and }), Mongoose doesn't clone the $and. Then Query.prototype.and() uses push() to add onto the $and array, which modifies the existing $and array.

We already have some logic in place from #12944 that shallow clones $and, $or if they're set, but that only currently kicks in if there's an existing $and / $or. With this PR, we'll do a shallow clone on $and, $or if they exist on the user's provided query filter.

Examples

if (isPOJO(from[key])) {
to[key] = { ...from[key] };
} else {
to[key] = from[key];

Check warning

Code scanning / CodeQL

Prototype-polluting function

Properties are copied from [from](1) to [to](2) without guarding against prototype pollution.
Copy link
Contributor

@sderrow sderrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a couple thoughts.

@vkarpov15 vkarpov15 merged commit 3526799 into master May 11, 2024
@hasezoey hasezoey deleted the vkarpov15/gh-14567 branch May 11, 2024 15:33
vkarpov15 added a commit that referenced this pull request May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter is mutated in place by Query modifiers

3 participants