ppkarwasz commented on code in PR #42:
URL: https://github.com/apache/commons-xml/pull/42#discussion_r3856976913
##########
src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java:
##########
@@ -356,6 +380,40 @@ void transformerDeniesUnlisted() {
}
}
+ @Test
+ @Tag("trax")
+ void transformerParsesOptedInImportHardened() {
+ // The opted-in module carries an external DTD reference; parsed on
the floor the DTD is empty, so its entity cannot expand into the output.
+ final TransformerFactory factory = hardenedTransformerFactory();
+ factory.setURIResolver((href, base) ->
+ href != null && href.endsWith("included.xsl") ?
AttackTestSupport.resourceSource("included-with-entity.xsl") : null);
+ try {
+ final StringWriter sink = new StringWriter();
+
factory.newTemplates(AttackTestSupport.resourceSource("with-import.xsl")).newTransformer()
+ .transform(AttackTestSupport.streamSource("<root/>"), new
StreamResult(sink));
+
assertFalse(sink.toString().contains(AttackTestSupport.LEAKED_MARKER),
"opted-in stylesheet import leaked its external entity");
+ } catch (final TransformerException blocked) {
Review Comment:
That is correct: the resolver resolves an **empty** resource, but some
implementation don't like it (e.g. they was a valid `xsl;stylesheet` element)
and throw.
I improved the comment in
https://github.com/apache/commons-xml/pull/42/commits/cc3c0ad8e2d455c1cd918282c0614fed4fcde9fa
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]