最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
前端如何防止xss攻击
时间:2026-08-21 08:33:50 编辑:袖梨 来源:一聚教程网

过滤非法字符,例如:
// 过滤XSS反射型漏洞filterInputTxt: function (html) {html = html.replace(/(.*]+>.*)/g,""); // HTML标记html = html.replace(/([rn])[s]+/g, ""); // 换行、空格html = html.replace(//g, ""); // HTML注释html = html.replace(/['"‘’“”!@#$%^&*{}!¥()()×+=]/g, ""); // 非法字符html = html.replace("alert","");html = html.replace("eval","");html = html.replace(/(.*javascript.*)/gi,"");if (html === "") {html = "你好";}return html;}