如何使用JAXB防止XML实体注入

我引用Prevent XXE Attack with JAXB此链接,

但仍然是 kiwan 工具,在xif.createXMLStreamReader(soapHeader.getsource())行中向我显示非常严重的漏洞,因此,如果有人知道,请帮助我。

我的代码如下:

SoapHeader soapHeader = ((SoapMessage) message).getsoapHeader();

 XMLInputFactory xif = XMLInputFactory.newFactory();
 xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,false);
 xif.setProperty(XMLInputFactory.SUPPORT_DTD,false);

XMLStreamReader soapHeaderXsr = xif.createXMLStreamReader(soapHeader.getsource());
unmarshaller.unmarshal(soapHeaderXsr);

谢谢。

gaoyangqusi 回答:如何使用JAXB防止XML实体注入

我通过添加额外的XMLInputFactory属性来解决此问题:-

  

xif.setProperty(XMLInputFactory.SUPPORT_DTD,false);

防止XXE的最安全方法始终是完全禁用DTD(外部实体)。

将DTD属性设置为false,以获取更多信息,请参阅此link

现在解决我的代码漏洞

谢谢

本文链接:https://www.f2er.com/3154254.html

大家都在问