Skip to content

Commit 00e5fa5

Browse files
authored
Update index.js
1 parent b2e4633 commit 00e5fa5

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

routes/index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports.index = function (req, res, next) {
3434
});
3535
};
3636

37-
// Vulnerable code:
37+
// Insert new vulnerable code:
3838

3939

4040
exports.loginHandler = function (req, res, next) {
@@ -136,6 +136,29 @@ exports.get_account_details = function(req, res, next) {
136136
return res.render('account.hbs', profile)
137137
}
138138

139+
// New NoSQL Injection vulnerability - added for Snyk testing
140+
/*
141+
exports.getUserById = function(req, res, next) {
142+
// Get the user ID from query parameters
143+
const userId = req.query.id;
144+
145+
// Directly use user input in MongoDB operator without sanitization
146+
// This is vulnerable if userId is something like: {"$ne": null}
147+
User.findOne({_id: userId}, function(err, user) {
148+
if (err) return next(err);
149+
150+
if (!user) {
151+
return res.status(404).send('User not found');
152+
}
153+
154+
return res.render('user_profile', {
155+
title: 'User Profile',
156+
user: user
157+
});
158+
});
159+
};
160+
*/
161+
139162
exports.save_account_details = function(req, res, next) {
140163
// get the profile details from the JSON
141164
const profile = req.body
@@ -238,7 +261,7 @@ exports.create = function (req, res, next) {
238261
};
239262

240263
// Insert new vulnerable code:
241-
/*
264+
242265
exports.destroy = function (req, res, next) {
243266
Todo.findById(req.params.id, function (err, todo) {
244267

@@ -279,7 +302,7 @@ exports.update = function (req, res, next) {
279302
});
280303
});
281304
};
282-
*/
305+
283306

284307
// ** express turns the cookie key to lowercase **
285308
exports.current_user = function (req, res, next) {

0 commit comments

Comments
 (0)