feat(query): make sanitizeProjection prevent projecting in paths deselected in the schema#14691
feat(query): make sanitizeProjection prevent projecting in paths deselected in the schema#14691
Conversation
…lected in the schema
hasezoey
left a comment
There was a problem hiding this comment.
@hasezoey what do you think about this PR, is this a reasonable feature and do you think it's reasonable to ship in 8.5?
i think it is reasonable to ship it with 8.5.0.
i personally have not used this yet, but wouldnt this (according to the test cases) completely disable find().select("+field -field"), or is this just for fields which have a schema select: false?
as a side note, i had tried to search for option sanitizeProjection in the documentation, and the only mention of this is in Query.prototype.setOptions as The following options are only for find(), findOne(), findById(), findOneAndUpdate(), findOneAndReplace(), findOneAndDelete(), and findByIdAndUpdate():, no documentation about what this option does.
Summary
sanitizeProjection option currently exists to prevent cases like
select({ name: '$password' }), which would cause thenameproperty to contain the value of thepasswordproperty in newer versions of MongoDB.While that is helpful,
sanitizeProjectioncan do a bit more to prevent inclusion of sensitive data when the projection is potentially untrusted. With this PR, ifsanitizeProjectionis enabled, there is no way to project in a field that's deselected withselect: falsein the schema definition. Ifpasswordhas{ type: String, select: false }andsanitizeProjectionis set, thenselect('+password'),select('password'), etc. will be ignored.@hasezoey what do you think about this PR, is this a reasonable feature and do you think it's reasonable to ship in 8.5?
Examples