-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Defending against query selector injections for v6.0 #10430
Conversation
…an object One alternative fix for #3944
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think option two would be better since option 1 has the potential to break people's code from a standard use.
I have a few thoughts:
Examples of point 2:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people will more likely use option 2 in their existing applications, but I think providing both options and letting people choose what they prefer is a good idea.
A third option would be to set the option on a schema path which will sanitize that path by default unless mentioned otherwise.
const userSchema = new Schema({
username: { type: String, sanitizeFilter: true },
password: { type: String, sanitizeFilter: true },
age: Number
});
The following is a rant regarding how we protect ourselves from that attack: In general, we categorize our APIs in two different categories:
We take the
We have an items collection, each item has a Someone with enough time can get the cost even though we're not selecting it by bruteforcing the filter:
|
2 different approaches for defending against query selector injections in Mongoose 6:
sanitizeFilter
option, likesanitizeProjection
, that removes all query selectors from queries by default, unless you wrap the query selector in aquerySelector()
function call.For example:
The upside is that it is easy for us to add
sanitizeFilter
as a global option. But then any queries that use query selectors, even legitimate ones, will break.Query#eq()
, and allow passing an object toQuery#eq()
,Query#lt()
, etc.For example:
I was working on approach (1) for a while, but I recently came up with approach (2). The downside of approach (2) is that it requires query chaining and isn't easy to "turn on" with one global option. But I think it is a less obtrusive approach for handling mixed trusted and untrusted data, like:
What do you think @IslandRhythms @AbdelrahmanHafez , (1) or (2), or both, or neither?