java-html-sanitizer
java-html-sanitizer copied to clipboard
img tag with data in src attribute is not working
I am facing issue with processing of tag for offsite url pattern.
We have requirement to show embedded image coming from some source. Post sanitization it's data part is trimmed.
Expected is:
but with sanitization on output coming is
<img width="383" height="127" />
I tried with below modification but it's not working. \s*(?:(?:ht|f)tps?://|mailto:|data:)[\p{L}\p{N}][\p{L}\p{N}\p{Zs}.#@$%+&;:-_~,?=/!()]+\s
If you could help in updating regular pattern to include "data:image/png;base64,binarydata".
Thanks for your support.
What is your policy?
I had the same issue but I could fix it with a policy like this using just "data" for protocol.
new HtmlPolicyBuilder() .allowCommonBlockElements() .allowCommonInlineFormattingElements() .allowStandardUrlProtocols() .allowUrlProtocols("data") .allowStyling() .allowElements("img", "a") .allowAttributes("src", "alt", "width", "height") .onElements("img") .allowAttributes("href").onElements("a") .disallowElements("script", "input") .requireRelNofollowOnLinks() .toFactory();