大師兄回來了 - Microsoft Web Protection Library 4.3.0
Microsoft Web Protection Library曾經是.NET Framework防禦XSS攻擊的最佳外掛,但在AntiXSS 4.2.1版(2012年)中它做了一個重大行為的改變,即GetSafeHtmlFragment方法會完完整整的過濾所有HTML Tag,換句話說,它不在只是過濾高風險性的HTML Tag,例如:<script />。
Microsoft Web Protection Library 4.3.0
經過二年的反應,2014/6/2官方終於更新了Microsoft Web Protection Library 4.3.0,而且又改回原始白名單的方式。
下載:Microsoft Anti-Cross Site Scripting Library V4.3
也可以直接由NuGet直接下載使用。
測試程式碼
Action方法:
public ActionResult Test()
{
return View();
}
[HttpPost]
[ValidateInput(false)]
public ActionResult Test(FormCollection form)
{
ViewBag.SafeHtmlFrag = Sanitizer.GetSafeHtmlFragment(form["content"])
return View();
}
[ValidateInput(false)]此屬性有極高安全性風險。這裡只是為了測試方便。
View Page:
@{
ViewBag.Title = "Test";
}
<h2>Test</h2>
@ViewBag.SafeHtmlFrag
<br />
@using (Html.BeginForm("Test", "Home"))
{
<input type="text" name="content" id="content" />
<input type="submit"/>
}

自从点Net搞了这套安全机制,所有基于html的编辑器在点Net平台上全部作废了。Good Job
回覆刪除