DOMPurify在标签之间保留文本||仅删除标签

时间:2019-12-13 15:42:28

标签: javascript xss html-injections dompurify

我有一个测试字符串。

const html = '{%remove%} useful {{remove}} <svg></p><style><a id="</style><img src=1 onerror=alert(1)>"> keep';

我正在尝试删除所有html内容和 {{}} {%% } 。但我想在字符串上保留有用保持字样。

const purifyConfig = {
    FORBID_TAGS: ['{{', '{%',],
    SAFE_FOR_TEMPLATES: true,
    RETURN_TRUSTED_TYPE: true,
    ALLOW_DATA_ATTR: false,
    KEEP_CONTENT: true,
};
const clean = DOMPurify.sanitize(html, purifyConfig);

清除结果为空字符串。 我应该使用什么配置来做到这一点?

0 个答案:

没有答案
相关问题