Skip to content

Dylan Fixing Issues #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 123 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test": "snyk test"
},
"dependencies": {
"adm-zip": "0.4.7",
"adm-zip": "0.5.2",
"body-parser": "1.9.0",
"cfenv": "^1.0.4",
"consolidate": "0.14.5",
Expand Down Expand Up @@ -46,7 +46,8 @@
"stream-buffers": "^3.0.1",
"tap": "^11.1.3",
"typeorm": "^0.2.24",
"validator": "^13.5.2"
"validator": "^13.5.2",
"stimulus_reflex": "3.4.1"
},
"devDependencies": {
"browserify": "^13.1.1",
Expand Down
44 changes: 6 additions & 38 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,8 @@ exports.index = function (req, res, next) {
});
};

// Vulnerable code:

exports.loginHandler = function (req, res, next) {
if (validator.isEmail(req.body.username)) {
User.find({ username: req.body.username, password: req.body.password }, function (err, users) {
if (users.length > 0) {
const redirectPage = req.body.redirectPage
const session = req.session
const username = req.body.username
return adminLoginSuccess(redirectPage, session, username, res)
} else {
return res.status(401).send()
}
});
} else {
return res.status(401).send()
}
};


if (validator.isEmail(req.body.username)) {
User.find({ username: req.body.username, password: req.body.password }, function (err, users) {
if (users.length > 0) {
const redirectPage = req.body.redirectPage
const session = req.session
const username = req.body.username
return adminLoginSuccess(redirectPage, session, username, res)
} else {
return res.status(401).send()
}
});
} else {
return res.status(401).send()
};

// Fixed code: validator.escape() is used to sanitize the input parameters (username and password) before using them in the database query.
/*

exports.loginHandler = function (req, res, next) {
// Validate if the username is in email format
if (validator.isEmail(req.body.username)) {
Expand Down Expand Up @@ -98,7 +63,7 @@ exports.loginHandler = function (req, res, next) {
return res.status(401).send("Unauthorized");
}
};
*/


function adminLoginSuccess(redirectPage, session, username, res) {
session.loggedIn = 1
Expand Down Expand Up @@ -356,7 +321,10 @@ exports.about_new = function (req, res, next) {
};

// Add new Vulnerable code:

exports.vulnerable_xss_reflected = function (req, res) {
const userInput = req.query.name;
res.send(`<h1>Hello ${userInput}</h1>`);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Cross-site Scripting (XSS)

Unsanitized input from an HTTP parameter flows into send, where it is used to render an HTML page returned to the user. This may result in a Cross-Site Scripting attack (XSS).

Line 326 | CWE-79 | Priority score 806 | Learn more about this vulnerability
Data flow: 8 steps

Step 1 - 5

const userInput = req.query.name;

Step 6 - 8

res.send(`<h1>Hello ${userInput}</h1>`);

};


// Prototype Pollution
Expand Down
Loading