Skip to content

Commit

Permalink
Merge pull request cliftonc#196 from arosboro/issue#102_xss
Browse files Browse the repository at this point in the history
Include sanitizer project for filtering of xss vulnerabilities
  • Loading branch information
richtera committed Apr 18, 2013
2 parents 220159e + 73e3ee0 commit ff189b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion modules/core/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var rootpath = process.cwd() + '/',
calipso = require(path.join(rootpath, 'lib/calipso')),
Query = require("mongoose").Query,
utils = require('connect').utils,
sanitizer = require('sanitizer'),
merge = utils.merge;

exports = module.exports = {
Expand Down Expand Up @@ -186,10 +187,18 @@ function getContent(req, options, next) {
text = "<span title='" + req.t("Double click to edit content block ...") + "' class='content-block' id='" + c._id + "'>" +
text + "</span>";
}
text = sanitizer.sanitize(text);

next(null, text);

} else {
// Sanitize strings
var prop;
for (var prop in c) {
if (typeof c[prop] === 'string') {
c[prop] = sanitizer.sanitize(c[prop]);
}
}

// Just return the object
next(null, c);
Expand Down Expand Up @@ -1028,4 +1037,4 @@ function install(next) {
function scheduledPublish(args, next) {
calipso.info("Scheduled publish: " + args);
next();
}
}
9 changes: 9 additions & 0 deletions modules/core/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var rootpath = process.cwd() + '/',
path = require('path'),
calipso = require(path.join(rootpath, 'lib/calipso')),
roles = require('./user.roles'),
sanitizer = require('sanitizer'),
Query = require("mongoose").Query,
everyauth = require("everyauth");

Expand Down Expand Up @@ -959,6 +960,14 @@ function userProfile(req, res, template, block, next) {
return;
}

// Sanitize user object
var prop;
for (var prop in u) {
if (typeof u[prop] === 'string') {
u[prop] = sanitizer.sanitize(u[prop]);
}
}

if (req.session.user && req.session.user.isAdmin) {
res.menu.adminToolbar.addMenuItem(req, {name:'List', weight:2, path:'list', url:'/user/list', description:'List users ...', security:[], icon:"icon-list-3"});
res.menu.adminToolbar.addMenuItem(req, {name:'Edit', weight:1, path:'edit', url:'/user/profile/' + username + '/edit', description:'Edit user details ...', security:[], icon:"icon-pencil-2"});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"everyauth":"0.3.x",
"adm-zip":"0.1.x",
"node-xml":"1.0.x",
"knox":"0.0.x"
"knox":"0.0.x",
"sanitizer":"0.0.15"
},
"optionalDependencies":{
"bcrypt":"0.7.x",
Expand Down

0 comments on commit ff189b3

Please sign in to comment.