mirror of
https://github.com/cnodejs/nodeclub.git
synced 2025-12-08 19:55:55 +00:00
使用xss模块来过滤主题及回复内容
This commit is contained in:
parent
6680c2baac
commit
d497dc63f9
@ -195,7 +195,7 @@ function get_reply_by_id(id, cb) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
reply.content = Showdown.parse(Util.escape(str));;
|
||||
reply.content = Util.xss(Showdown.parse(str));
|
||||
return cb(err, reply);
|
||||
});
|
||||
});
|
||||
@ -250,7 +250,7 @@ function get_replies_by_topic_id(id, cb) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
replies[i].content = Showdown.parse(Util.escape(str));
|
||||
replies[i].content = Util.xss(Showdown.parse(str));
|
||||
proxy.emit('reply_find');
|
||||
});
|
||||
});
|
||||
|
||||
@ -59,7 +59,7 @@ exports.index = function (req, res, next) {
|
||||
if (err) {
|
||||
return ep.emit(err);
|
||||
}
|
||||
topic.content = Showdown.parse(Util.escape(content));
|
||||
topic.content = Util.xss(Showdown.parse(content));
|
||||
ep.emit('@user');
|
||||
});
|
||||
});
|
||||
|
||||
12
libs/util.js
12
libs/util.js
@ -1,3 +1,5 @@
|
||||
var xss = require('xss');
|
||||
|
||||
exports.format_date = function (date, friendly) {
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() + 1;
|
||||
@ -77,3 +79,13 @@ exports.escape = function(html){
|
||||
.replace(/^\n\n/, '')
|
||||
.replace(/\n\n$/, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* 过滤XSS攻击代码
|
||||
*
|
||||
* @param {string} html
|
||||
* @return {string}
|
||||
*/
|
||||
exports.xss = function (html) {
|
||||
return xss(html);
|
||||
};
|
||||
|
||||
@ -12,7 +12,8 @@
|
||||
"validator": "0.3.7",
|
||||
"ndir": ">=0.1.3",
|
||||
"nodemailer": "0.3.5",
|
||||
"data2xml": "0.4.0"
|
||||
"data2xml": "0.4.0",
|
||||
"xss": ">=0.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"should": "*",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user