我是靠谱客的博主 难过长颈鹿,这篇文章主要介绍过滤关键字防止XSS攻击,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static string ClearXSS(string str) { string returnValue = str; if (string.IsNullOrEmpty(returnValue)) { return string.Empty; } ///过滤CSS Expression AND 过滤JavsScript returnValue = Regex.Replace(returnValue, @"<(style|script)[^<>]*?>.*?</(style|script)>", string.Empty, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Singleline); ///过滤JS 事件 如:οnclick="alert('123');" returnValue = Regex.Replace(returnValue, @"(?<=<[^>]+?)b(onclick|ondatabinding|ondblclick|ondisposed|oninit|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onprerender|onunload|onerror|onfocus)b(?=.*?)", string.Empty, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Singleline); //过滤iframe|frame returnValue = Regex.Replace(returnValue, @"<(iframe|frame)[^>]*>|</(iframe|frame)>", string.Empty, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Singleline); return returnValue; }

 

转载于:https://www.cnblogs.com/mingjia/p/6044055.html

最后

以上就是难过长颈鹿最近收集整理的关于过滤关键字防止XSS攻击的全部内容,更多相关过滤关键字防止XSS攻击内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部