@@ -36,7 +36,6 @@ exports.index = function (req, res, next) {
36
36
37
37
// Vulnerable code:
38
38
39
-
40
39
exports . loginHandler = function ( req , res , next ) {
41
40
if ( validator . isEmail ( req . body . username ) ) {
42
41
User . find ( { username : req . body . username , password : req . body . password } , function ( err , users ) {
@@ -238,7 +237,7 @@ exports.create = function (req, res, next) {
238
237
} ;
239
238
240
239
// Insert new vulnerable code:
241
- /*
240
+
242
241
exports . destroy = function ( req , res , next ) {
243
242
Todo . findById ( req . params . id , function ( err , todo ) {
244
243
@@ -279,7 +278,7 @@ exports.update = function (req, res, next) {
279
278
} ) ;
280
279
} ) ;
281
280
} ;
282
- */
281
+
283
282
284
283
// ** express turns the cookie key to lowercase **
285
284
exports . current_user = function ( req , res , next ) {
@@ -358,6 +357,24 @@ exports.about_new = function (req, res, next) {
358
357
} ) ;
359
358
} ;
360
359
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
+
361
378
// Prototype Pollution
362
379
363
380
///////////////////////////////////////////////////////////////////////////////
0 commit comments