Reputation: 1942
Learning the basics of MongoDB, I read that MongoDB is vulnerable to injection attacks out-of-the-box. In node, this can be prevented using the help of the module mongo-sanitize. So far, so good. Now let's add Mongoose to the equation.
If we are using Mongoose
I remember reading that Mongoose can prevent injections to some extent, but I don't know the specifics, or if it is redundant to sanitize against Mongoose.
Upvotes: 4
Views: 492
Reputation: 4057
Like the article mentioned the problem arises when the users doesn't send a string like
'bergur' and 'myawesomepassword' but instead sends {"$ne": null}
for usernames and passwords.
If you create a schema and define username and password as strings, then Mongoose will convert it to string and you avoid the problem.
Regarding the where injection, mongo-sanitize wouldn't help you there. The solution is simply not to ever use the $where operator
So to simply answer your question:
Upvotes: 3