Small example of masking script injection

  • 2020-03-29 23:40:58
  • OfStack

String filtering
 
static public string HtmlEncode(string str) 
{ 
str = str.Replace("&", "&"); 
str = str.Replace("<", "<"); 
str = str.Replace(">", ">"); 
str = str.Replace("'", "''"); 
str = str.Replace("*", ""); 
str = str.Replace("n", "<br/>"); 
str = str.Replace("rn", "<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 = " There is no "; } 
return str.Trim(); 
} 

Related articles: