Skip to content

Commit d052293

Browse files
authored
Update index.js
1 parent 347181e commit d052293

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

routes/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ exports.index = function (req, res, next) {
3636

3737
// Vulnerable code:
3838

39-
4039
exports.loginHandler = function (req, res, next) {
4140
if (validator.isEmail(req.body.username)) {
4241
User.find({ username: req.body.username, password: req.body.password }, function (err, users) {
@@ -238,7 +237,7 @@ exports.create = function (req, res, next) {
238237
};
239238

240239
// Insert new vulnerable code:
241-
/*
240+
242241
exports.destroy = function (req, res, next) {
243242
Todo.findById(req.params.id, function (err, todo) {
244243

@@ -279,7 +278,7 @@ exports.update = function (req, res, next) {
279278
});
280279
});
281280
};
282-
*/
281+
283282

284283
// ** express turns the cookie key to lowercase **
285284
exports.current_user = function (req, res, next) {
@@ -358,6 +357,24 @@ exports.about_new = function (req, res, next) {
358357
});
359358
};
360359

360+
/*
361+
// 🚨 NoSQL Injection Vulnerability: Directly using user input as query
362+
exports.vulnerable_nosql_injection = function (req, res, next) {
363+
const query = req.body || {};
364+
365+
// This is dangerous: attacker can send {"$ne": null} to bypass auth
366+
User.findOne(query, function (err, user) {
367+
if (err) return next(err);
368+
if (!user) {
369+
return res.status(404).send("User not found");
370+
}
371+
return res.status(200).send("Welcome " + user.username);
372+
});
373+
};
374+
*/
375+
376+
377+
361378
// Prototype Pollution
362379

363380
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)