【发布时间】:2020-12-14 20:22:04
【问题描述】:
我对 JAXB 非常陌生,在我们的代码审计中,有人建议使用 JAXB 防止 XXE 攻击。我找到了相关答案:Prevent XXE Attack with JAXB
我现有的代码如下所示:
if (properties.getProperty(MANIFEST) != null && !properties.getProperty(MANIFEST).isEmpty()) {
String manifestString = properties.getProperty(MANIFEST);
ByteArrayInputStream is = new ByteArrayInputStream(manifestString.getBytes());
try {
this.manifest = (Manifest) getJaxbContext().createUnmarshaller().unmarshal(is);
}
catch (JAXBException e) {
LOG.warn("There was an error trying to convert xml String to Manifest - {}", e.getMessage(), e);
}
}
根据答案,我应该使用 XMLStreamReader 和一些属性 false,而不是使用 ByteArrayInputStream。
在建议的答案中,它说:
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource("src/xxe/input.xml"));
我不明白“src/xxe/input.xml”是什么以及我的解决方案需要什么。谁能解释一下?
【问题讨论】: