org.xml.sax.SAXNotRecognizedException:无法识别属性'http://javax.xml.XMLConstants/property/accessExternalDTD'

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

我想防止XXE攻击在我的项目中。它是在Java 7(no maven)和jboss-as-7服务器上运行的旧api项目。但是在执行过程中我得到了错误:org.xml.sax.SAXNotRecognizedException:无法识别属性'http://javax.xml.XMLConstants/property/accessExternalDTD'

 org.xml.sax.SAXNotRecognizedException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.

15:19:02,845 ERROR [stderr] (http-localhost-127.0.0.1-8080-3)   at org.apache.xerces.jaxp.validation.ValidatorImpl.setProperty(ValidatorImpl.java:218)

15:19:02,846 ERROR [stderr] (http-localhost-127.0.0.1-8080-3)   at com.uid.kua.web.KUARestController.authenticateAtAUA(KUARestController.java:118)

15:19:02,847 ERROR [stderr] (http-localhost-127.0.0.1-8080-3)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

15:19:02,847 ERROR [stderr] (http-localhost-127.0.0.1-8080-3)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

15:19:02,848 ERROR [stderr] (http-localhost-127.0.0.1-8080-3)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

15:19:02,849 ERROR [stderr] (http-localhost-127.0.0.1-8080-3)   at java.lang.reflect.Method.invoke(Method.java:606)

我已经搜索过它,每个论坛都说这是一个错误,其含义有所不同。我没有找到任何与此异常相关的解决方案。请帮忙。预先感谢。

java xml xml-parsing java-api xxe
1个回答
0
投票

最后我解决了。如果有帮助,我会发布答案。通过在线解决方案后,我无法检测到导致上述错误的主要问题。为了防止xxe,我们需要一些已定义的属性,例如:XMLConstants.ACCESS_EXTERNAL_DTDXMLConstants.ACCESS_EXTERNAL_SCHEMA

我们需要xercesjaxp-api jars来粘贴xml,并通过设置上述一些属性来防止api提供的xxe来解析xml。在JDK 7之前,这些已包含在JDK 7及更高版本中。因此,我们不需要在项目类路径中的jar上方导入。

就我而言,我使用的是jboss-as-7.1.1.Final作为应用服务器,它也有自己的xerces jar (org.apache.xerces。。但是java也带有它自己的xerces和jaxp实现(com.sun.xerces。)。因此,在部署战争时,我们会遇到上述错误,因为这两个jar都在jboss加载它自己的xerces jar时发生冲突。

解决方案:我们需要通过在jboss / org / apache / xerces / main / modules.xml文件中进行更改来exclude jboss xerces实现。注释掉以下行:

> <module xmlns="urn:jboss:module:1.1" name="org.apache.xerces">    
> <!--
>     <resources>
>         <resource-root path="xercesImpl-2.9.1-jbossas-1.jar"/>
>         Insert resources here
>     </resources>
> -->
>     <dependencies>
>         <module name="javax.api"/>
>     </dependencies>
> 
> </module>

现在部署并运行您的应用程序。编码愉快。

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