顯示具有 AntiXSS 標籤的文章。 顯示所有文章
顯示具有 AntiXSS 標籤的文章。 顯示所有文章

大師兄回來了 - Microsoft Web Protection Library 4.3.0

大師兄回來了 - 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"/>
 }