我使用Antisamy来验证HTML。我的政策允许iframe,例如youtube视频。问题是 - 如果标签为空(如下所示):
<iframe src="//www.youtube.com/embed/uswzriFIf_k?feature=player_detailpage" allowfullscreen></iframe>
比清洁之后会像这样:
<iframe src="//www.youtube.com/embed/uswzriFIf_k?feature=player_detailpage" allowfullscreen/>
但它应该有正常的结束标记。
这打破了页面上的所有内容。 我已经将我的指令设置为使用大部分HTML但不使用XML:
<directives>
<directive name="omitXmlDeclaration" value="true"/>
<directive name="omitDoctypeDeclaration" value="true"/>
<directive name="maxInputSize" value="200000"/>
<directive name="nofollowAnchors" value="true" />
<directive name="validateParamAsEmbed" value="true" />
<directive name="useXHTML" value="false"/>
<directive name="embedStyleSheets" value="false"/>
<directive name="connectionTimeout" value="5000"/>
<directive name="maxStyleSheetImports" value="3"/>
<directive name="formatOutput" value="false"/>
</directives>
但这没有用。
UPD:在解析器之间切换和使用指令仍然没有给出任何结果。
UPD2:这是我配置的一部分,负责处理iframe
标记:
<tag name="iframe" action="validate">
<attribute name="src">
<regexp-list>
<regexp name="youtube"/>
<regexp name="slideshare"/>
</regexp-list>
</attribute>
<attribute name="allowfullscreen">
<regexp-list>
<regexp name="anything"/>
</regexp-list>
</attribute>
<attribute name="scrolling">
<regexp-list>
<regexp name="anything"/>
</regexp-list>
</attribute>
<attribute name="marginwidth">
<regexp-list>
<regexp name="anything"/>
</regexp-list>
</attribute>
<attribute name="marginheight">
<regexp-list>
<regexp name="anything"/>
</regexp-list>
</attribute>
<attribute name="frameborder">
<regexp-list>
<regexp name="anything"/>
</regexp-list>
</attribute>
<attribute name="style"/>
</tag>
有什么想法吗?
答案 0 :(得分:0)
试试这个 -
<tag name="iframe" action="validate"/>
并在此列表中添加标签 -
<allowed-empty-tags>
<literal-list>
<literal value="iframe"/>
</literal-list>
</allowed-empty-tags>
答案 1 :(得分:0)
我遇到了同样的问题。就我而言,这是由于AntiSamy政策具有以下指令:
<directive name="useXHTML" value="true" />
根据OWASP文档,将以XHTML格式而不是常规HTML输出经过清理的数据。 请参阅: https://www.owasp.org/index.php/AntiSamy_Directives
将该值更改为false将允许将经过清理的输出作为有效HTML提供。块级元素将不会被缩短并成为无效标记。