I was trying to find out how to prevent MongoDB injections, and I came across this. So, the vulnerable code here is
app.post('/', function (req, res) {
db.users.find({username: req.body.username, password: req.body.password}, function (err, users) { // This line!
// TODO: handle the rest
});
});
Could I protect against a MongoDB injection by verifying that the POST
body username and password are both strings, and not objects?
Are there any other ways to inject data into a MongoDB database?