赞
踩
1.正则表达式验证
public static bool sqlValidate(string sql)
{
string badStr = @"\b(update|delete|insert|or|not|like|trancate|into|exec|master|drop|execute|net user|xp_cmdshell|go|create|grant|group_concat|restore|backup|net +localgroup +administrators|iframe|cookie|location|prompt|confirm|script|<a.*|<img.*)\b";
Regex reg = new Regex(badStr, RegexOptions.IgnoreCase);
return reg.IsMatch(sql);
}
3.过滤
前端过滤
function htmlEncode(str) {
var s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, "&")
.replace(/</g, "<");
.replace(/>/g, ">");
.replace(/ /g, " ");
.replace(/\'/g, "'");
.replace(/\"/g, """);
.replace(/\n/g, "<br>");
return s;
}
//解码
function htmlDecode(str) {
var s = "";
if (str.length == 0) return "";
.replace(/>/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/ /g, " ")
.replace(/'/g, "\'")
.replace(/"/g, "\"")
.replace(/<br>/g, "\n");
return s;
}
后端过滤
public static string FilterHTML(string html)
{
if (html == null)
return "";
//将<转义成
string strResult = html;
strResult = strResult.Replace("<", "<")
.Replace(">", ">")
.Replace("&", "&")
.Replace("\"", """);
return strResult;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。