Java 为恶意xml设置Apache CXF总线属性
我正在尝试为恶意xml设置CXF总线属性,如下所示Java 为恶意xml设置Apache CXF总线属性,java,spring,web-services,cxf,Java,Spring,Web Services,Cxf,我正在尝试为恶意xml设置CXF总线属性,如下所示 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:http="http://cxf.apache.org/transport
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<cxf:bus>
<cxf:properties>
<entry key="org.apache.cxf.stax.maxAttributeSize" value="1"/>
<entry key="org.apache.cxf.stax.maxChildElements" value="1"/>
<entry key="org.apache.cxf.stax.maxElementDepth" value="1"/>
<entry key="org.apache.cxf.stax.maxAttributeCount" value="1"/>
<entry key="org.apache.cxf.stax.maxTextLength" value="1"/>
<entry key="org.apache.cxf.stax.maxElementCount" value="1"/>
</cxf:properties>
</cxf:bus>
</beans>
这些属性似乎不是由CXF获取的。以上代码位于spring上下文xml文件中。每当我执行包含多个元素和子元素的post请求时,CXF不会抛出任何错误。我使用的是CXF版本3.1.1我已经在带有java 1.6和java 1.8的Tomcat服务器上测试了CXF 2.7.13和3.1.6的总线属性,在这两种情况下,XML请求都被阻止,如文档所述 确保woodstook和stax库位于类路径中。CXF将XML检查委托给这些库。如果服务器有XML解析器,它就拥有XML解析器。它们必须在XML解析器服务器之前(如果可用)。检查 我将详细说明配置,以便您可以检查您的配置 CXF依赖项(常春藤格式) Book.java
@XmlRootElement(name = "Book")
public class Book {
private String name;
public String getName() {return name;}
public void setName(String name) {this.name = name;}
}
请求测试
POST /test
Content-Type:application/xml
<Book><name>aaaa</name></Book>
如果删除
部分,将应用CXF,并将处理XML示例
aaaa123
使用cxf 3.2.4在总线级别进行配置对我来说根本不起作用。 在端点级别进行配置后,一切都像一个符咒:
<jaxws:endpoint address="/myEndpoint" id="myEndpoinId" implementor="#myEndpoint">
<jaxws:properties>
<entry key="org.apache.cxf.stax.maxTextLength" value="536870912"/>
</jaxws:properties> (...)
(...)
这可能很简单,但您使用的是版本>CXF 2.7.4我使用的是版本3.1.1确保woodstock
在类路径中并且正在使用org.apache.cxf.stax.allowInsecureParser
必须是false
(这是默认值)我将woodstock添加到pom文件中,我可以在类路径中看到它。如何设置属性“org.apache.cxf.stax.allowInsecureParser”。我在cxf站点上没有看到任何文档?ThanksIt是一个环境变量。若之前并没有设置,那个么不要担心,因为默认值为false。还要检查服务器的部署选项,以确保woodstock已加载。CXF文档说明此库将用于执行验证感谢:)。经过一些调试后,我看到在总线上设置了属性,但我认为我缺少端点(中列出的端点)。我认为REST的模式是一样的?我有疑问,但jax rs服务器也运行XML过滤器。我添加了一个示例,如果您删除了标记,那么您将为这些限制设置谁的cxf属性?然后将使用默认值。如果您想对每台服务器应用不同的限制,请配置一个总线
,并使用bus=“#yourbus”
从服务器引用它。否,我指的是您给出的其余示例和int,您说您通过删除标记获得了错误“最大元素深度限制(1)”。如何在不设置属性的情况下实现这一点。
POST /test
Content-Type:application/xml
<Book><name>aaaa</name></Book>
JAXBException occurred : Maximum Element Depth limit (1) Exceeded. Maximum Element Depth limit (1) Exceeded.
aaaa123
<jaxws:endpoint address="/myEndpoint" id="myEndpoinId" implementor="#myEndpoint">
<jaxws:properties>
<entry key="org.apache.cxf.stax.maxTextLength" value="536870912"/>
</jaxws:properties> (...)