为了应对XSS漏洞的攻击我们有必要对暴露在外面的参数进行合法性检查,可以使用如下js函数:

// 字符串去掉非法字符
removeInvalidChar : function(str)
{
  var codeArray = new Array(" ","<",">","'","\"",";","(",")","{","}","[","]",":","\\","/","$");
   //循环替换非法字符
  for (i = 0; i < codeArray.length; i++) {
    while (str.indexOf(codeArray[i]) != -1) {
         str = str.replace(codeArray[i], '');
    }
  }
  return str;
}

  

相关文章:

  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2021-12-29
相关资源
相似解决方案