owasp消毒剂生成意外结果

bejyjqdl  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(323)

我正在使用owasp消毒剂对输入数据进行清理。以下是我使用的策略

return new HtmlPolicyBuilder()
                    .allowElements("a", "label", "h1", "h2", "h3", "h4", "h5", "h6",
                            "p", "i", "b", "u", "strong", "em", "small", "big", "pre", "code",
                            "cite", "samp", "sub", "sup", "strike", "center", "blockquote",
                            "hr", "br", "col", "font", "span", "div", "img",
                            "ul", "ol", "li", "dd", "dt", "dl", "tbody", "thead", "tfoot",
                            "table", "td", "th", "tr", "colgroup", "fieldset", "legend")
                    .allowAttributes("src", "alt", "align", "title", "hspace", "vspace").onElements("img")
                    .allowAttributes("href", "target").onElements("a")
                    .allowAttributes("border", "cellpadding", "cellspacing", "style", "class").onElements("table")
                    .allowAttributes("colspan", "rowspan", "style", "class", "align", "valign").onElements("td")
                    .allowAttributes("border", "height", "width").globally()
                    .allowStandardUrlProtocols()
                    .requireRelNofollowOnLinks()
                    .allowStyling()
                    .toFactory();

所以当我的意见是 <a>test</a> ,我希望它会返回相同的结果,因为我允许使用“a”标记。但是,它只返回“test”。这是我的毕业证书
编译组:“com.googlecode.owasp java html sanitizer”,名称:“owasp java html sanitizer”,版本:“20191001.1”
我也尝试过不允许属性(“脚本”)。也没用。有什么想法吗?谢谢。

epggiuax

epggiuax1#

所以当我的输入是test时,我希望它会返回相同的结果,因为我允许使用“a”标记。但是,它只返回“test”。
如果没有提供属性,则默认情况下不允许使用某些元素。只需将以下子句添加到策略生成器:

.allowWithoutAttributes("a")

它会移除 a 来自内部的元素 HtmlPolicyBuilder.skipIfEmpty 跳过的示例集 a , font , img , input ,和 span 默认情况下(请参见 HtmlPolicyBuilder.DEFAULT_SKIP_IF_EMPTY ).

相关问题