【问题标题】:Sanitize Html with base64 image (and convert it to an image)使用 base64 图像清理 Html(并将其转换为图像)
【发布时间】:2018-11-24 09:27:12
【问题描述】:

我有一个带有 TinyMCE Html Editor 的 WebApp,它允许用户从网页输入一些 html。图像可以粘贴并编码为 base64。 在将用户输入保存到数据库之前,我使用OWASP java-html-sanitizer 丢弃潜在的危险代码(javascript,...)。

图像的 base64 字符串中的某些字符被转义,当我尝试取回图像时(使用 apache commons Base64)我无法获得有效图像。

这是我解码图像的代码:

byte[] b;
String s = html;
b = s.getBytes(Utility.UTF8);
b = org.apache.commons.codec.binary.Base64.decodeBase64(b);

对于 HtmlSanitizer,我没有做任何特别的事情,只是按照 Ebay Policy Example 的建议允许 base64 图像 here

【问题讨论】:

    标签: base64 tinymce owasp html-sanitizing


    【解决方案1】:

    啊,正如 here 建议的那样,我需要“在 base64 解码之前进行 HTML 解码”。

    我已经尝试过使用 apache common StringEscapeUtils:

    org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(html);
    

    它正在工作。太好了。

    【讨论】:

      【解决方案2】:

      allowedSchemes: [ 'data']allowedSchemesByTag: { img: [ 'data' ]} 可用于允许img 标签接受/允许base64。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-06-10
        • 1970-01-01
        • 2015-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-28
        相关资源
        最近更新 更多