攻击方式:
在页面展示的内容中掺杂js代码,以获取页面信息。
预防措施:
转换生成的js特殊字符
后端预防:
Node
npm包工具 xss 实现
npm i xss --save // 安装成功后 引入xss const xss = require("xss") // 使用xss工具过滤特殊字符 const content = xss(string)
前端预防
使用js封装函数转换特殊字符
/*传入html字符串源码即可*/ function htmlEscape(text){ return text.replace(/[<>"&]/g, (match, pos, originalText) => { switch(match){ case "<": return "<"; case ">":return ">"; case "&":return "&"; case "\"":return """; } }); }

我的微信
爱生活、爱学习的小伙伴可以通过扫一扫二维码添加我的个人微信一起交流!
评论