Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ public static VersionDefinitionXml load(String xml) throws Exception {
private static VersionDefinitionXml load(InputStream stream) throws Exception {

XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
// Harden the XMLInputFactory against XXE
try {
xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
} catch (IllegalArgumentException ignored) {
// Property not supported by this implementation; ignore.
}
try {
xmlFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE);
} catch (IllegalArgumentException ignored) {
// Property not supported by this implementation; ignore.
}
XMLStreamReader xmlReader = xmlFactory.createXMLStreamReader(stream);

xmlReader.nextTag();
Expand All @@ -602,6 +613,22 @@ private static VersionDefinitionXml load(InputStream stream) throws Exception {
Unmarshaller unmarshaller = ctx.createUnmarshaller();

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Harden the SchemaFactory against XXE and external resource loading
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (Exception ignored) {
// Feature not supported; ignore.
}
try {
factory.setProperty("http://apache.org/xml/properties/accessExternalDTD", "");
} catch (IllegalArgumentException ignored) {
// Property not supported by this implementation; ignore.
}
try {
factory.setProperty("http://apache.org/xml/properties/accessExternalSchema", "");
} catch (IllegalArgumentException ignored) {
// Property not supported by this implementation; ignore.
}
Schema schema = factory.newSchema(new StreamSource(xsdStream));
unmarshaller.setSchema(schema);

Expand Down