@@ -34,43 +34,8 @@ exports.index = function (req, res, next) {
34
34
} ) ;
35
35
} ;
36
36
37
- // Vulnerable code:
38
-
39
- exports . loginHandler = function ( req , res , next ) {
40
- if ( validator . isEmail ( req . body . username ) ) {
41
- User . find ( { username : req . body . username , password : req . body . password } , function ( err , users ) {
42
- if ( users . length > 0 ) {
43
- const redirectPage = req . body . redirectPage
44
- const session = req . session
45
- const username = req . body . username
46
- return adminLoginSuccess ( redirectPage , session , username , res )
47
- } else {
48
- return res . status ( 401 ) . send ( )
49
- }
50
- } ) ;
51
- } else {
52
- return res . status ( 401 ) . send ( )
53
- }
54
- } ;
55
-
56
-
57
- if ( validator . isEmail ( req . body . username ) ) {
58
- User . find ( { username : req . body . username , password : req . body . password } , function ( err , users ) {
59
- if ( users . length > 0 ) {
60
- const redirectPage = req . body . redirectPage
61
- const session = req . session
62
- const username = req . body . username
63
- return adminLoginSuccess ( redirectPage , session , username , res )
64
- } else {
65
- return res . status ( 401 ) . send ( )
66
- }
67
- } ) ;
68
- } else {
69
- return res . status ( 401 ) . send ( )
70
- } ;
71
-
72
37
// Fixed code: validator.escape() is used to sanitize the input parameters (username and password) before using them in the database query.
73
- /*
38
+
74
39
exports . loginHandler = function ( req , res , next ) {
75
40
// Validate if the username is in email format
76
41
if ( validator . isEmail ( req . body . username ) ) {
@@ -98,7 +63,7 @@ exports.loginHandler = function (req, res, next) {
98
63
return res . status ( 401 ) . send ( "Unauthorized" ) ;
99
64
}
100
65
} ;
101
- */
66
+
102
67
103
68
function adminLoginSuccess ( redirectPage , session , username , res ) {
104
69
session . loggedIn = 1
@@ -356,7 +321,10 @@ exports.about_new = function (req, res, next) {
356
321
} ;
357
322
358
323
// Add new Vulnerable code:
359
-
324
+ exports . vulnerable_xss_reflected = function ( req , res ) {
325
+ const userInput = req . query . name ;
326
+ res . send ( `<h1>Hello ${ userInput } </h1>` ) ;
327
+ } ;
360
328
361
329
362
330
// Prototype Pollution
0 commit comments