andrew4582

Strip Dangerous Tags

Jul 13th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. public static string strip_dangerous_tags(string text_with_tags)
  2.         {
  3.             string s = Regex.Replace(text_with_tags,
  4.                                  @"<script", "<scrSAFEipt", RegexOptions.IgnoreCase);
  5.             s = Regex.Replace(s, @"</script", "</scrSAFEipt", RegexOptions.IgnoreCase);
  6.             s = Regex.Replace(s, @"<object", "<obSAFEject", RegexOptions.IgnoreCase);
  7.             s = Regex.Replace(s, @"</object", "</obSAFEject", RegexOptions.IgnoreCase);
  8.             s = Regex.Replace(s, @"<embed", "<emSAFEbed", RegexOptions.IgnoreCase);
  9.             s = Regex.Replace(s, @"</embed", "</emSAFEbed", RegexOptions.IgnoreCase);
  10.             s = Regex.Replace(s, @"onabort", "onSAFEabort", RegexOptions.IgnoreCase);
  11.             s = Regex.Replace(s, @"onblur", "onSAFEblur", RegexOptions.IgnoreCase);
  12.             s = Regex.Replace(s, @"onchange", "onSAFEchange", RegexOptions.IgnoreCase);
  13.             s = Regex.Replace(s, @"onclick", "onSAFEclick", RegexOptions.IgnoreCase);
  14.             s = Regex.Replace(s, @"ondblclick", "onSAFEdblclick", RegexOptions.IgnoreCase);
  15.             s = Regex.Replace(s, @"onerror", "onSAFEerror", RegexOptions.IgnoreCase);
  16.             s = Regex.Replace(s, @"onfocus", "onSAFEfocus", RegexOptions.IgnoreCase);
  17.  
  18.             s = Regex.Replace(s, @"onkeydown", "onSAFEkeydown", RegexOptions.IgnoreCase);
  19.             s = Regex.Replace(s, @"onkeypress", "onSAFEkeypress", RegexOptions.IgnoreCase);
  20.             s = Regex.Replace(s, @"onkeyup", "onSAFEkeyup", RegexOptions.IgnoreCase);
  21.  
  22.             s = Regex.Replace(s, @"onload", "onSAFEload", RegexOptions.IgnoreCase);
  23.  
  24.             s = Regex.Replace(s, @"onmousedown", "onSAFEmousedown", RegexOptions.IgnoreCase);
  25.             s = Regex.Replace(s, @"onmousemove", "onSAFEmousemove", RegexOptions.IgnoreCase);
  26.             s = Regex.Replace(s, @"onmouseout", "onSAFEmouseout", RegexOptions.IgnoreCase);
  27.             s = Regex.Replace(s, @"onmouseup", "onSAFEmouseup", RegexOptions.IgnoreCase);
  28.             s = Regex.Replace(s, @"onmouseup", "onSAFEmouseup", RegexOptions.IgnoreCase);
  29.  
  30.             s = Regex.Replace(s, @"onreset", "onSAFEresetK", RegexOptions.IgnoreCase);
  31.             s = Regex.Replace(s, @"onresize", "onSAFEresize", RegexOptions.IgnoreCase);
  32.             s = Regex.Replace(s, @"onselect", "onSAFEselect", RegexOptions.IgnoreCase);
  33.             s = Regex.Replace(s, @"onsubmit", "onSAFEsubmit", RegexOptions.IgnoreCase);
  34.             s = Regex.Replace(s, @"onunload", "onSAFEunload", RegexOptions.IgnoreCase);
  35.  
  36.             return s;
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment