JavaScript过滤XSS
var filterXSS=function(oriStr){if(!oriStr){
return oriStr;
}
var charCodes=['3c','3e','27','22','28','29','60',{format:'script{}',chr:'3a'}];//要转义字符的16进制ASCII码
var xssChars=[],filterChars=[],tmpFormat='{}',tmpChr;
for(var i=0;i<charCodes.length;i++){
if('string'==typeof charCodes){
tmpFormat='{}';
tmpChr=charCodes;
}else{
tmpFormat=charCodes.format;
tmpChr=charCodes.chr
}
xssChars.push(tmpFormat.replace('{}','\\u00'+tmpChr));
xssChars.push(tmpFormat.replace('{}','%'+tmpChr));//1次encode
xssChars.push(tmpFormat.replace('{}','%25'+tmpChr));//2次encode
filterChars.push(tmpFormat.replace('{}','&#x'+tmpChr+';'));
filterChars.push(tmpFormat.replace('{}','%26%23x'+tmpChr+'%3B'));//1次encode
filterChars.push(tmpFormat.replace('{}','%2526%2523x' + tmpChr + '%253B'));//2次encode
}
for(var i=0;i<xssChars.length;i++){
oriStr=oriStr.replace(new RegExp(xssChars,'gi'),filterChars);
}
//预防script:
oriStr=oriStr.replace(/script[\u000d\u000a\u0020]+\:/,'script:');
return oriStr;
} good学到了 师傅这代码很熟悉呀
https://apps.game.qq.com/ams/wxlogin_redirect.html?s_url=
Dem0ns 发表于 2021-3-2 13:33
师傅这代码很熟悉呀
对的,我没标原创啊
页:
[1]