七月网

escapexml

七月网1940

主要介绍了"如何屏蔽script注入",主要涉及到如何屏蔽script注入方面的内容.

escapexml

字符串过滤

static public string HtmlEncode(string str)

{

str= str.Replace("&","&");

str= str.Replace("<","&lt;");

str= str.Replace(">","&gt");

str= str.Replace("'","''");

str= str.Replace("*","");

str= str.Replace("\n","<br/>");

str= str.Replace("\r\n","<br/>");

//str= str.Replace("?","");

str= str.Replace("select","");

str= str.Replace("insert","");

str= str.Replace("update","");

str= str.Replace("delete","");

str= str.Replace("create","");

str= str.Replace("drop","");

str= str.Replace("delcare","");

if(str.Trim().ToString()==""){ str="无";}

return str.Trim();

}

//第二种方法,使用jstl表达式,在输出的时候用

<c:out escapeXml="true"/>输出即可

//jQuery中如何屏蔽script?

//jQuery屏蔽script注入

1: var html="<script>alert('asdfasdf')<\/script>";

2:$("#content").text(html);那么会发生什么情况解决办法很简单就是把这些特殊字符进行转义也就是<变成<>变成>使用jquery对字符进行转义这样就可以了

1:<head>

2:<script>

3: var html="<script>alert('asdfasdf')<\/scipt>";

4: html=$("#x").text(html).html();

5:$("#content").append("<div>"+html+"</div>");

6:</script>

7:</head>

8:<body>

9:<spanid="x"style="display:none"></span>

10:<divid="content"></div> 11:

</body>//jQuery屏蔽script注入

1: var html="<script>alert('asdfasdf')<\/script>";

2:$("#content").text(html);那么会发生什么情况解决办法很简单就是把这些特殊字符进行转义也就是<变成<>变成>使用jquery对字符进行转义这样就可以了

1:<head>

2:<script>

3: var html="<script>alert('asdfasdf')<\/scipt>";

4: html=$("#x").text(html).html();

5:$("#content").append("<div>"+html+"</div>");

6:</script>

7:</head>

8:<body>

9:<spanid="x"style="display:none"></span>

10:<divid="content"></div> 11:

</body>

文章分享结束,escapexml和如何屏蔽script注入的答案你都知道了吗?欢迎再次光临本站哦!

上一篇live.cn邮箱登陆

下一篇1hhhhhhh