Skip to content

Commit

Permalink
JENA-2331: isolate setting of XMLInputFactory properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bvosburgh-tq committed Jun 1, 2022
1 parent 14c97d7 commit bbfc3b1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,26 @@ public static XMLReader createXMLReader() throws ParserConfigurationException, S
* Initialize an XMLInputFactory to jena settings.
*/
public static void initXMLInputFactory(XMLInputFactory xf) {
// This disables DTDs entirely for the factory.
// All DTDs are silently ignored; takes precedence over ACCESS_EXTERNAL_DTD
setXMLInputFactoryProperty(xf, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);

// disable external entities (silently ignore)
setXMLInputFactoryProperty(xf, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);

// Disable external DTDs (files and HTTP) - errors unless SUPPORT_DTD is false.
setXMLInputFactoryProperty(xf, XMLConstants.ACCESS_EXTERNAL_DTD, "");
}

/**
* Catch any {@link IllegalArgumentException}, log it, and continue.
*/
private static void setXMLInputFactoryProperty(XMLInputFactory xf, String name, Object value) {
try {
// This disables DTDs entirely for the factory.
// All DTDs are silently ignored; takes precedence over ACCESS_EXTERNAL_DTD
xf.setProperty(XMLInputFactory.SUPPORT_DTD, false);

// Disable external DTDs (files and HTTP) - errors unless SUPPORT_DTD is false.
xf.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
// disable external entities (silently ignore)
xf.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
} catch(IllegalArgumentException ex){
Log.error(JenaXMLInput.class, "Problem setting StAX property", ex);
xf.setProperty(name, value);
} catch(IllegalArgumentException ex) {
Log.error(JenaXMLInput.class, "Problem setting StAX property - name: \"" +
name + "\" - value: \"" + value + "\" - error: " + ex.getMessage());
}
}

Expand Down

0 comments on commit bbfc3b1

Please sign in to comment.