java-html-sanitizer icon indicating copy to clipboard operation
java-html-sanitizer copied to clipboard

img tag with data in src attribute is not working

Open kadianravi opened this issue 7 years ago • 2 comments

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.

kadianravi avatar Apr 09 '18 14:04 kadianravi

What is your policy?

mikesamuel avatar Mar 18 '19 15:03 mikesamuel

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();

afbustamante avatar Aug 02 '24 12:08 afbustamante