zoukankan      html  css  js  c++  java
  • js解决跨站点脚本编制问题

    1.前台处理(容易绕过):

    <script type="text/javascript">
     $(document).ready(function(){
     var url=window.location.href;
    
     window.location.href=HTMLEnCode(url);
    });
    
    function HTMLEnCode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&/g, "&gt;");
    s = s.replace(/</g, "");
    s = s.replace(/>/g, "");
    s = s.replace(/ /g, "");
    s = s.replace(/"/g, "");
    s = s.replace(/'/g, "");
    s = s.replace(/
    /g, "");
    s = s.replace(///g, "");
    s = s.replace(/(/g, "");
    s = s.replace(/)/g, "");
    s = s.replace(/=/g, "");
    
    return s;
    } });
     </script>

    2.后台处理:

        /**
         * 危险字符过滤方法
         * @param str
         * @return
         * @throws Exception
         */
        public static String dangerousCharacterFilter(String str) {
            //一种解决SQL盲注的后台过虑,其方式就是将可能出现的非法字符进行规制
            //java代码替换特殊字符
            //str="^&h\/!@#$%^&*()+|/jgfj&%fgd''$#$@!)(}|";
            if(str!=null){
                str = str.replaceAll("(\|)", "");
                str = str.replaceAll("(\&)", "");
                str = str.replaceAll("(\;)", "");
                str = str.replaceAll("(\$)", "");
                str = str.replaceAll("(\%)", "");
                str = str.replaceAll("(\@)", "");
                str = str.replaceAll("(\')", "");
                str = str.replaceAll("(\")", "");
                str = str.replaceAll("(\>)", "");
                str = str.replaceAll("(\<)", "");
                str = str.replaceAll("(\))", "");
                str = str.replaceAll("(\()", "");
                str = str.replaceAll("(\+)", "");
                //str = str.replaceAll("(\CR)", "");  //回车符 ASCII 0x0d
                //str = str.replaceAll("(\LF)", "");  //换行 ASCII 0x0a
                str = str.replaceAll("(\,)", "");
                str = str.replaceAll("(\\)", "");
                str = str.replaceAll("(\#|$)", "");
           }
           return str;
        }

    3.添加过滤器(暂时没做)

  • 相关阅读:
    Hibernate检索策略与检索方式
    获取分组后的TOP 1和TOP N记录
    Oracle 高级排序函数 和 高级分组函数
    Java中的字符串常量池
    代码的完整性:打印1到最大的n位数
    代码的完整性:数值的整数次方
    递归和循环:矩形覆盖
    位运算:二进制中1的个数
    递归和循环:变态跳台阶
    递归和循环:跳台阶
  • 原文地址:https://www.cnblogs.com/shuilangyizu/p/7273652.html
Copyright © 2011-2022 走看看