Skip to content

Commit b801c13

Browse files
author
KUMAR Jitendra
committed
added xss middleware
1 parent 4441f47 commit b801c13

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

config/lib/guard/jwt.guard.js

-13
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,4 @@ module.exports = (app, ENV) => {
1212
// //@ pass api without validating
1313
// path: unlessRoutes
1414
// }));
15-
16-
//@ error handler for unauthorized routes rejected by JWT
17-
app.use(function (err, req, res, next) {
18-
if (err.name === 'UnauthorizedError') {
19-
20-
res.status(401).render('404',{
21-
status:'failed',
22-
requestType: 'Unauthorized request'
23-
});
24-
}else{
25-
next();
26-
}
27-
});
2815
}

config/lib/guard/xss.guard.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ const validator = require('express-validator');
22

33
module.exports = (app) => {
44
//@ secure application from xxs attacks
5-
// app.use(validator());
6-
// //@
7-
// app.use(function(req, res, next) {
8-
// for (var item in req.body) {
9-
// req.sanitize(item).escape();
10-
// }
11-
// next();
12-
// });
5+
app.use(validator());
6+
//@
7+
app.use(function(req, res, next) {
8+
for (var item in req.body) {
9+
req.sanitize(item).escape();
10+
}
11+
next();
12+
});
1313
}

config/lib/helper_lib/middleware.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class Middleware {
4646
//@ check password length
4747
//@ password should contain a special character
4848
//@ password should not contain white space
49-
if (length < minLength || length > maxLength || havingSpace || !havingSpecialChar) {
49+
50+
//@ if you want to add special character check you can include !havingSpecialChar in condition
51+
if (length < minLength || length > maxLength || havingSpace) {
5052

5153
resObj.message = length < minLength ? "password length shoud be not be less than " + minLength
5254
: length > maxLength ? "password should not be greater than " +maxLength

modules/user_profile/controllers/user.account.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const path = require('path'),
88

99
exports.register = (req, res) => {
1010

11+
console.log(req.body);
1112
let userProfileModel = new UserProfileModel(req.body);
1213

1314
//@ save object to database

modules/user_profile/routes/routes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ router
2323

2424
module.exports = {
2525
router: router,
26-
base: '/api/user-profile'
26+
base: '/api/user'
2727
};
2828

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"scripts": {
77
"test": "mocha --timeout=7000",
88
"start": "node server.js",
9-
"dev":"NODE_ENV=local node server.js",
10-
"devmon":"NODE_ENV=local nodemon"
9+
"dev": "NODE_ENV=local node server.js",
10+
"devmon": "NODE_ENV=local nodemon"
1111
},
1212
"author": "Jitendra",
1313
"license": "MIT",
@@ -27,7 +27,8 @@
2727
"mongoose": "^4.11.13",
2828
"morgan": "^1.8.2",
2929
"multer": "^1.3.0",
30-
"socket.io": "^2.0.3"
30+
"socket.io": "^2.0.3",
31+
"supervisor": "^0.12.0"
3132
},
3233
"devDependencies": {
3334
"chai": "^4.1.2",

0 commit comments

Comments
 (0)