3

我知道我们可以通过在 JAXB 中将抽象类 XMLInputFactory 中的属性 IS_SUPPORTING_EXTERNAL_ENTITIES 设置为 false 来防止 XXE 攻击。

我也看过这个stackoverflow answer

我的问题是,

如何在 spring 应用程序加载时创建 XMLInputFactory 的实例并将此 IS_SUPPORTING_EXTERNAL_ENTITIES 属性设置为 false。并且那个特定的 XMLInputFactory 实例应该只用于所有使用 javax.xml.bind.annotation 包的类的所有 JAXB 转换。

4

1 回答 1

5

Spring 使用 RequestMappingHandlerAdapter,它是一个 AbstractHandlerMethodAdapter,它支持带有签名的 HandlerMethods——方法参数和返回类型,在 @RequestMapping 中定义。

有 7 七个 HttpMessageConverter,其中之一是 Jaxb2RootElementHttpMessageConverter

Jaxb2RootElementHttpMessageConverter 来自 spring-web 包。

从 spring-web 的 3.2.8 版本开始,Jaxb2RootElementHttpMessageConverter 将 processExternalEntities 设置为 false,这又将 XMLInputFactory 属性 IS_SUPPORTING_EXTERNAL_ENTITIES 设置为 false。

参考 :

http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-web/3.2.8.RELEASE/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java?av=f

答案使用
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.2.8.RELEASE</version> </dependency>

于 2015-02-09T20:30:32.787 回答