Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AntiXss.HtmlEncode vs AntiXss.GetSafeHtmlFragment

Can anyone please let me know the difference between these two? AntiXss.HtmlEncode() vs AntiXss.GetSafeHtmlFragment()

like image 410
Biki Avatar asked Oct 18 '10 12:10

Biki


People also ask

What is GetSafeHtmlFragment?

GetSafeHtmlFragment (AntiXss v4.0) returns HTML fragments with tags intact: Sanitizer.GetSafeHtmlFragment("<b>hello2</b><script>") //Output: <b>hello2</b>

What is Antixssencoder HtmlEncode?

HtmlEncode(String, Boolean) Encodes the specified string for use as text in HTML markup and optionally specifies whether to use HTML 4.0 named entities. HtmlEncode(String, TextWriter) Encodes the specified string for use as text in HTML markup and outputs the string by using the specified text writer.

What is AntiXSS library?

The Anti-Cross Site Scripting Library (AntiXSS) is an encoding library designed to assist developers in protecting their ASP.NET web-based applications from Cross-Site Scripting (XSS) attacks. It differs from most encoding libraries in that it uses the white-listing technique to provide protection against XSS attacks.


1 Answers

HtmlEcode actually encodes tags:

AntiXss.HtmlEncode("<b>hello</b><script>");
//Output: &lt;b&gt;hello&lt;/b&gt;&lt;script&gt;

GetSafeHtmlFragment (AntiXss v4.0) returns HTML fragments with tags intact:

Sanitizer.GetSafeHtmlFragment("<b>hello2</b><script>")
//Output: <b>hello2</b>

Update

Many consider the latest version of Microsoft's AntiXSS library broken. I've started using HTML Sanitizer as a decent replacement.

like image 132
Brian Chavez Avatar answered Sep 27 '22 18:09

Brian Chavez