复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16public 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攻击内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复