mganss / HtmlSanitizer

Cleans HTML to avoid XSS attacks
MIT License
1.52k stars 198 forks source link

System.NullReferenceException on sanitize style #426

Closed mannfredz closed 11 months ago

mannfredz commented 1 year ago

This HTML generates an exception ;

Sanitizer.Sanitize("<div style=\"border-width:1px;border-right-width:px;\"></div>");

System.NullReferenceException: Object reference not set to an instance of an object. at AngleSharp.Css.Values.CssPeriodicValue 1.get_CssText() at AngleSharp.Css.Dom.CssProperty.get_Value() at AngleSharp.Css.Dom.CssProperty.ToCss(TextWriter writer, IStyleFormatter formatter) at AngleSharp.Css.CssStyleFormatter.AngleSharp.IStyleFormatter.BlockDeclarations(IEnumerable 1 declarations) at AngleSharp.Css.Dom.CssStyleDeclaration.ToCssBlock(IStyleFormatter formatter) at AngleSharp.Css.Dom.CssStyleDeclaration.ToCss(TextWriter writer, IStyleFormatter formatter) at AngleSharp.FormatExtensions.ToCss(IStyleFormattable style, IStyleFormatter formatter) at Ganss.Xss.HtmlSanitizer.SanitizeStyle(IElement element, String baseUrl) at Ganss.Xss.HtmlSanitizer.DoSanitize(IHtmlDocument dom, IParentNode context, String baseUrl) at Ganss.Xss.HtmlSanitizer.SanitizeDom(String html, String baseUrl) at Ganss.Xss.HtmlSanitizer.Sanitize(String html, String baseUrl, IMarkupFormatter outputFormatter)

tiesont commented 1 year ago

Helps to provide some context:

mannfredz commented 1 year ago

Hi,

mganss commented 1 year ago

This seems to be an issue within AngleSharp.Css. I have reported here: https://github.com/AngleSharp/AngleSharp.Css/issues/129

mganss commented 11 months ago

I've released 8.0.690-beta which depends on the fixed AngleSharp.Css version.