我在这里做什么有什么问题吗?这是我第一次处理这样的事情,我只是想确保我理解所有风险等不同的方法。白名单,防止在C#中使用WMD控制XSS
我正在使用WMD获取用户输入,并且我用文字控件显示它。 因为它是不可编辑输入一次,我将存储HTML而不是降价,
input = Server.HTMLEncode(stringThatComesFromWMDTextArea)
然后运行类似的标签我希望用户能够使用以下。
// Unescape whitelisted tags.
string output = input.Replace("<b>", "<b>").Replace("</b>", "</b>")
.Replace("<i>", "<i>").Replace("</i>", "</i>");
编辑下面是我在做什么目前:
public static string EncodeAndWhitelist(string html)
{
string[] whiteList = { "b", "i", "strong", "img", "ul", "li" };
string encodedHTML = HttpUtility.HtmlEncode(html);
foreach (string wl in whiteList)
encodedHTML = encodedHTML.Replace("<" + wl + ">", "<" + wl + ">").Replace("</" + wl + ">", "</" + wl + ">");
return encodedHTML;
}
- 请问我在这里做让我免受XSS什么?
- 有没有其他的考虑 应该做?
- 是否有正常的 标签到白名单的好名单?
该代码将不适用于“IMG”标签,因为替换“<img>”不允许“src”属性“ – David 2010-01-20 20:23:56