Skip to content

Commit

Permalink
XML External Entity (XXE) injection in XmlConverter. Thanks to Stepha…
Browse files Browse the repository at this point in the history
…n Siano for the patch.

Conflicts:
	camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
  • Loading branch information
davsclaus committed Mar 2, 2015
1 parent 7360aad commit 367d53e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ public SAXSource toSAXSourceFromStream(StreamSource source) {
} catch (Exception e) {
LOG.warn("SAXParser doesn't support the feature {} with value {}, due to {}.", new Object[]{javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, "true", e});
}
try {
sfactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
} catch (SAXException e) {
LOG.warn("SAXParser doesn't support the feature {} with value {}, due to {}."
, new Object[]{"http://xml.org/sax/features/external-general-entities", false, e});
}
sfactory.setNamespaceAware(true);
SAXParser parser = sfactory.newSAXParser();
xmlReader = parser.getXMLReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,25 @@ private void sendEntityMessage(Object message) throws Exception {
Exchange exchange = list.get(0);
String xml = exchange.getIn().getBody(String.class);
assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);




try {
endpoint.reset();
endpoint.expectedMessageCount(1);

template.sendBody("direct:start2", message);
fail("Expect an exception here");

assertMockEndpointsSatisfied();

list = endpoint.getReceivedExchanges();
exchange = list.get(0);
xml = exchange.getIn().getBody(String.class);
assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);
} catch (Exception ex) {
// expect an exception here
assertTrue("Get a wrong exception", ex instanceof CamelExecutionException);
// the file could not be found
assertTrue("Get a wrong exception cause", ex.getCause() instanceof TransformerException);
}

}


Expand Down

0 comments on commit 367d53e

Please sign in to comment.