ppkarwasz commented on code in PR #42:
URL: https://github.com/apache/commons-xml/pull/42#discussion_r3857471430


##########
src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java:
##########
@@ -352,7 +361,41 @@ void transformerDeniesUnlisted() {
                     .transform(AttackTestSupport.streamSource("<root/>"), new 
StreamResult(sink));
             
assertFalse(sink.toString().contains(AttackTestSupport.LEAKED_MARKER), 
"unlisted stylesheet import leaked");
         } catch (final TransformerException blocked) {
-            // Acceptable: rejected at compile rather than resolved to empty.
+            // Throwing is an acceptable outcome, since it doesn't leak the 
marker.
+        }
+    }
+
+    @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:
   I rechecked an apparently these throws are now stale: both Xalan and Saxon 
are happy with the kind of empty resource they receive.



-- 
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]

Reply via email to