服务器端消息数据安全性

清理服务器端的消息内容的最佳方法是从客户端接收作为查询字符串参数之一?此消息也意味着要重新发送到其他连接的客户端,因此它在服务器或客户端的代码执行或注入(JavaScript或HTML)方面是安全的。     
已邀请:
为了保护node.js免受XSS攻击,我从片段jade中借用了这个:
/**
 * Escape the given string of `html`.
 *
 * @param {String} html
 * @return {String}
 * @api private
 */

function sanitize(html){
    return String(html)
        .replace(/&(?!w+;)/g, '&')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
}
P.S:您应该始终进行适当的服务器端过滤     
您可以使用node-validator,它看起来像是一个更全面的解决方案。     

要回复问题请先登录注册