首页 新闻 会员 周边

如何过滤提交内容中的iframe

0
悬赏园豆:20 [已解决问题] 解决于 2012-03-01 09:50

请问如何过滤提交内容中的iframe

观海云不远的主页 观海云不远 | 初学一级 | 园豆:89
提问于:2012-02-23 09:16
< >
分享
最佳答案
0

转一个吧:

public  string wipeScript(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href\s*=.*javascript[^>\s]*", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on\w+=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"<input[\s\S]+</input *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"<style[\s\S]+</style *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<link[\s\S]+</link *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<(input|link|iframe|frameset|frame)[^>]*/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, string.Empty); //过滤<script></script>标记
html = regex6.Replace(html, string.Empty); //过滤input
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, string.Empty); //过滤iframe
html = regex5.Replace(html, string.Empty); //过滤frameset
html = regex7.Replace(html, string.Empty); //过滤iframe
html = regex8.Replace(html, string.Empty); //过滤frameset
html = regex2.Replace(html, " href="#" (<A>) 属性
return html;
}

来自:http://bbs.jsp163.com/forum.php?mod=viewthread&tid=27611

收获园豆:10
artwl | 专家六级 |园豆:16736 | 2012-02-23 09:42
其他回答(2)
0

详细点

sunlary | 园豆:934 (小虾三级) | 2012-02-23 09:24
0

如果你只是为了确保用户输入的string里没有不安全的html标签/属性的话:http://www.cnblogs.com/coderzh/archive/2010/06/24/AntiXSS.html

收获园豆:10
水牛刀刀 | 园豆:6350 (大侠五级) | 2012-02-23 10:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册