java - antisamy 解析器强制关闭标记

标签 java security html-parsing owasp antisamy

我使用 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>

有什么想法吗?

最佳答案

试试这个-

<tag name="iframe" action="validate"/>

并在这个列表中添加一个标签-

<allowed-empty-tags>
   <literal-list>
      <literal value="iframe"/>
   </literal-list>
</allowed-empty-tags>

参见 http://code.google.com/p/owaspantisamy/...

关于java - antisamy 解析器强制关闭标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19343035/

相关文章:

java - fragment 中 getDefaultSharedPreferences 上的 NullPointerException

java - 在 Android 上使用 AES 加密文件

javascript - 在 Java 中使用 Jsoup 检测 Javascript 库

java - 如何使用 jsoup 选择除第一个和最后一个之外的所有子项(具有相同的标签。例如表)

java - Eclipse Jbehave 报错

java - 无法加载驱动程序 java.sql.SQLException : No suitable driver found for jdbc

database - 安全存储 OpenID 标识符和 OAuth token

java - org.owasp.esapi.Encoder.encodeForHTML 和 org.owasp.esapi.Encoder.encodeForJavaScript 方法之间有什么区别

security - Elasticsearch、Apache Metron 和 Apache Spot 在网络安全方面有何技术差异?

c# - HTML敏捷包: Issues getting content of anchor tag within a string