zoukankan      html  css  js  c++  java
  • jqgrid跨站脚本漏洞解决

    问题描述:

      jqgrid版本4.5.2

      用户输入值为<script>alert(123)</script>时,jqgrid默认的展示方法会将字符串转换为dom元素,于是就产生了这样的情况

      

      一些不怀好意的人就会通过这些方法对项目发起攻击。

    如下提供两种修改方案:

      假设var strData = "<script>alert(123)</script>";是原数据

      (1)使用jqgrid的数据格式化方法(colModel.foramter)修改源数据,去掉特殊字符(推荐)

         {name: 'NAME', index: 'name',  hidden: false, formatter: formateHtml},

    function formatHtml(cellValue,option,cell){
    	if(undefined != cellValue && null != cellValue){
    		return escapeHTML(cellValue);
    	}
    	return "-";
    }
    
    function escapeHTML(a){
    	a = "" + a;
        return a.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");;
    }

      

      (2)修改jqgrid的源代码,在jqgrid调用formatter方法之前将数据格式化

        搜索

          var h = a.p.colModel[e];

        这句代码之后有一个

          if (h.formatter !== void 0) {

        在它们之间加上   

    if("string" === typeof d){
    	d = "" + d;
    	d = d.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");;
    }
    

      

    更多内容扩展

      https://www.cnblogs.com/phpstudy2015-6/p/6767032.html

  • 相关阅读:
    Intellij IDEA 配置Tomcat远程调试
    maven学习二(dependencies)
    maven学习一(HelloWorld工程)
    一致性hash在分布式系统中的应用
    理解TCP之Keepalive
    理解HTTP之keep-alive
    TCP/IP,http,socket,长连接,短连接
    图解 HTTP 协议
    PHP开发的一些趣事
    vue
  • 原文地址:https://www.cnblogs.com/chendeming/p/8365402.html
Copyright © 2011-2022 走看看