Veracode XML 外部实体参考 (XXE) 解组组织。w3c.dom.Element
Veracode XML External Entity Reference (XXE) unmarshaling org.w3c.dom.Element
我在解组 Element.
时从代码扫描审计 (Veracode) 中得到一个 XML 外部实体引用 (XXE) 漏洞
public static <T> T unMarshal(org.w3c.dom.Element content, Class<T> clazz) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (T) unmarshaller.unmarshal(content, clazz).getValue();
}
如何修复上述代码中 XML 外部实体引用 ('XXE') 的不当限制?
根据你的例子,你可以试试这个代码:
public static <T> T unMarshal(org.w3c.dom.Element content, Class<T> clazz) throws JAXBException, XMLStreamException {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
XMLInputFactory xmlif = XMLInputFactory.newFactory();
xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xmlif.createXMLStreamReader(content);
return (T) unmarshaller.unmarshal(xsr, clazz).getValue();
}
我认为上述解决方案可以解决与 (CWE 611) XML 外部实体引用相关的问题
我在解组 Element.
时从代码扫描审计 (Veracode) 中得到一个 XML 外部实体引用 (XXE) 漏洞 public static <T> T unMarshal(org.w3c.dom.Element content, Class<T> clazz) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
return (T) unmarshaller.unmarshal(content, clazz).getValue();
}
如何修复上述代码中 XML 外部实体引用 ('XXE') 的不当限制?
根据你的例子,你可以试试这个代码:
public static <T> T unMarshal(org.w3c.dom.Element content, Class<T> clazz) throws JAXBException, XMLStreamException {
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
XMLInputFactory xmlif = XMLInputFactory.newFactory();
xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xmlif.createXMLStreamReader(content);
return (T) unmarshaller.unmarshal(xsr, clazz).getValue();
}
我认为上述解决方案可以解决与 (CWE 611) XML 外部实体引用相关的问题