I have seen many solutions using XMLInputFactory, SAXParser and DocumentBuilderFactory. Our web service is spring and the only thing we do:
@Bean
public Jaxb2Marshaller unmarshaller() {
Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
unmarshaller.setContextPath("foo");
unmarshaller.setProcessExternalEntities(false);
return unmarshaller;
}
And then we pass this marshaller and unmarshaller to MarshallingPayloadMethodProcessor. So my question is, there is some property for Jaxb2Marshaller that will prevent DTD. Sort of:unmarshaller.setProperty(foo.SUPPORT_DTD, false);
We have a .xsd schema, but in the case of xml bomb, the object should be deleted due to validation, so it seems like this is not a solution.
source
share