OWASP 消毒剂产生意想不到的结果

问题描述 投票:0回答:1

我正在使用 OWASP sanitizer 对输入数据进行一些清理。以下是我使用的政策

             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”标签。但是,它仅返回“测试”。这是我的 gradle

编译组:'com.googlecode.owasp-java-html-sanitizer',名称:'owasp-java-html-sanitizer',版本:'20191001.1'

我也尝试过disallowAttributes(“script”)。它也不起作用。有任何想法吗?谢谢。

java xss owasp
1个回答
1
投票

因此,当我的输入被测试时,我希望它会返回相同的结果,因为我允许“a”标签。但是,它仅返回“测试”。

某些元素如果没有提供属性,则默认是不允许的。只需将以下子句添加到策略构建器即可:

.allowWithoutAttributes("a")

它将从内部

a
实例集中删除
HtmlPolicyBuilder.skipIfEmpty
元素,默认情况下会跳过
a
font
img
input
span
(请参阅
HtmlPolicyBuilder.DEFAULT_SKIP_IF_EMPTY
)。

© www.soinside.com 2019 - 2024. All rights reserved.