-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Closed
Copy link
Labels
backwards-breakingdiscussionIf you have any thoughts or comments on this issue, please share them!If you have any thoughts or comments on this issue, please share them!
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
In working on #14400, I got to thinking that the fact that update pipelines aren't casted may be risky for data integrity issues. Passing in untrusted data may lead to bypassing Mongoose casting entirely.
// If `req.body.updates` is an array, no casting, so can add arbitrary fields and incorrect types for existing fields
await User.findOneAndUpdate({ _id: req.body.id }, req.body.updates);We should consider making update pipelines opt-in, either using a mongoose.updatePipeline() helper:
await User.findOneAndUpdate({ _id: req.body.id }, mongoose.updatePipeline([{ $set: { name: 'foo' } }]));or with an updatePipeline option:
await User.findOneAndUpdate({ _id: req.body.id }, [{ $set: { name: 'foo' } }], { updatePipeline: true });What do you think @hasezoey @AbdelrahmanHafez ?
drew-vanta and adarshmadrecha
Metadata
Metadata
Assignees
Labels
backwards-breakingdiscussionIf you have any thoughts or comments on this issue, please share them!If you have any thoughts or comments on this issue, please share them!