一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

前端如何防止xss攻击

时间:2026-08-21 08:33:50 编辑:袖梨 来源:一聚教程网

前端防止xss攻击的方法:

过滤非法字符,例如:

// 过滤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;}

热门栏目