Skip to content

Commit b85f1b1

Browse files
authored
Merge pull request #931 from terrestris/fix-xml-parser-external-dtd-handling
Handle unsupported external DTD and schema properties
2 parents 382bad9 + 0450f3c commit b85f1b1

File tree

1 file changed

+12
-6
lines changed
  • shogun-gs-interceptor/src/main/java/de/terrestris/shogun/interceptor/util

1 file changed

+12
-6
lines changed

shogun-gs-interceptor/src/main/java/de/terrestris/shogun/interceptor/util/OgcXmlUtil.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,21 @@ public static Document getDocumentFromString(String xml) throws IOException {
8585
InputSource source = new InputSource(new StringReader(xml));
8686
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
8787

88-
// limit resolution of external entities, see https://rules.sonarsource.com/c/type/Vulnerability/RSPEC-2755
89-
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
90-
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
88+
try {
89+
// limit resolution of external entities, see https://rules.sonarsource.com/c/type/Vulnerability/RSPEC-2755
90+
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
91+
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
92+
} catch (IllegalArgumentException e) {
93+
log.error("External DTD/Schema access properties not supported:"
94+
+ e.getMessage());
95+
}
9196

9297
DocumentBuilder builder = factory.newDocumentBuilder();
9398
document = builder.parse(source);
94-
} catch (ParserConfigurationException | SAXException | IOException e) {
95-
throw new IOException("Could not parse input body " +
96-
"as XML: " + e.getMessage());
99+
} catch (IllegalArgumentException | ParserConfigurationException
100+
| SAXException | IOException e) {
101+
throw new IOException("Could not parse input body as XML: "
102+
+ e.getMessage());
97103
}
98104
return document;
99105
}

0 commit comments

Comments
 (0)