Is it possible to log or throw an error on an invalid tag instead of silently sanitize it?

128 views
Skip to first unread message

Will Herrmann

unread,
Nov 8, 2018, 7:02:35 PM11/8/18
to OWASP Java HTML Sanitizer Support
Say that I have an HTML block like this:

<foo><b>Hello</b></foo>

If I run I sanitize it (say with Sanitizers.FORMATTING.sanitize(html)), then it happily removes the <foo> tags, and doesn't even do any sort of logging.

Is it possible to log, or even throw an error when encountering an invalid tag instead of silently sanitizing it?

Mike Samuel

unread,
Nov 8, 2018, 7:06:37 PM11/8/18
to owasp-java-html-...@googlegroups.com
PolicyFactory.apply takes an HtmlChangeListener which should let you do what you need.  Specifically

voiddiscardedTag(T context, String elementName)
Called when a tag is discarded from the input.

--
You received this message because you are subscribed to the Google Groups "OWASP Java HTML Sanitizer Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to owasp-java-html-saniti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Will Herrmann

unread,
Nov 16, 2018, 2:47:52 PM11/16/18
to OWASP Java HTML Sanitizer Support
Thanks, that does exactly what I'm looking for!
To unsubscribe from this group and stop receiving emails from it, send an email to owasp-java-html-sanitizer-support+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages