Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(query): make sanitizeProjection prevent projecting in paths deselected in the schema #14691

Merged
merged 3 commits into from
Jul 3, 2024

Conversation

vkarpov15
Copy link
Collaborator

Summary

sanitizeProjection option currently exists to prevent cases like select({ name: '$password' }), which would cause the name property to contain the value of the password property in newer versions of MongoDB.

While that is helpful, sanitizeProjection can do a bit more to prevent inclusion of sensitive data when the projection is potentially untrusted. With this PR, if sanitizeProjection is enabled, there is no way to project in a field that's deselected with select: false in the schema definition. If password has { type: String, select: false } and sanitizeProjection is set, then select('+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

@vkarpov15 vkarpov15 added this to the 8.5 milestone Jun 25, 2024
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

@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.

@vkarpov15
Copy link
Collaborator Author

@hasezoey re: select('+field'), just for + and just for fields that have select: false in the schema. Other fields are fine. I also added a Query.prototype.sanitizeProjection method in 0904a18 and added docs with examples to address the docs issue.

@vkarpov15 vkarpov15 merged commit f48df23 into 8.5 Jul 3, 2024
51 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14333 branch July 3, 2024 16:17
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.

3 participants