This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new a7a9f7905df Fixes #9182. Document how to allow the file scheme in 
xslt-saxon stylesheets
a7a9f7905df is described below

commit a7a9f7905df088098d43d972943a0fba9e47bac4
Author: Jiří Ondrušek <[email protected]>
AuthorDate: Thu Dec 3 17:45:29 2026 +0100

    Fixes #9182. Document how to allow the file scheme in xslt-saxon stylesheets
    
    Since Camel 4.22 (CAMEL-24108) the xslt-saxon endpoint sets
    ACCESS_EXTERNAL_STYLESHEET to an empty string, so e.g. collection() on a
    file: URI fails with "URI scheme 'file' has been disallowed". Document the
    TransformerFactoryConfigurationStrategy way to allow it and cover both
    cases in the xslt-saxon integration test.
    
    Co-authored-by: jiriOndrusek-agent <[email protected]>
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../pages/reference/extensions/xslt-saxon.adoc     | 40 +++++++++++++++++++++
 .../xslt-saxon/runtime/src/main/doc/usage.adoc     | 35 ++++++++++++++++++
 .../xslt/saxon/it/XsltSaxonProducers.java}         | 26 +++++++-------
 .../component/xslt/saxon/it/XsltSaxonResource.java | 41 ++++++++++++++++++++++
 .../component/xslt/saxon/it/XsltSaxonTest.java     | 23 ++++++++++++
 5 files changed, 153 insertions(+), 12 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/xslt-saxon.adoc 
b/docs/modules/ROOT/pages/reference/extensions/xslt-saxon.adoc
index 70c5fd222d9..a54aa9fb55a 100644
--- a/docs/modules/ROOT/pages/reference/extensions/xslt-saxon.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/xslt-saxon.adoc
@@ -43,3 +43,43 @@ Or add the coordinates to your existing project:
 ifeval::[{doc-show-user-guide-link} == true]
 Check the xref:user-guide/index.adoc[User guide] for more information about 
writing Camel Quarkus applications.
 endif::[]
+
+[id="extensions-xslt-saxon-usage"]
+== Usage
+[id="extensions-xslt-saxon-usage-access-to-external-resources-from-stylesheets"]
+=== Access to external resources from stylesheets
+
+Since Camel 4.22 (Camel Quarkus 3.39.0), the `xslt-saxon` endpoint sets 
`XMLConstants.ACCESS_EXTERNAL_STYLESHEET` to an empty string on the Saxon 
`TransformerFactory`.
+Stylesheets that read external resources, for example via `collection()` on a 
`file:` URI, then fail with an error such as `URI scheme 'file' has been 
disallowed`.
+
+To allow the `file` scheme, configure the factory with a 
`TransformerFactoryConfigurationStrategy` bean.
+Camel calls the strategy after it applies its own security settings, so only 
the listed schemes are allowed.
+
+[source,java]
+----
+import javax.xml.XMLConstants;
+
+import jakarta.enterprise.inject.Produces;
+import jakarta.inject.Named;
+import jakarta.inject.Singleton;
+import org.apache.camel.component.xslt.TransformerFactoryConfigurationStrategy;
+
+public class XsltSaxonConfig {
+    @Produces
+    @Singleton
+    @Named("allowFileAccess")
+    TransformerFactoryConfigurationStrategy allowFileAccess() {
+        return (factory, endpoint) -> 
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file");
+    }
+}
+----
+
+Reference the bean from the endpoint:
+
+[source,java]
+----
+to("xslt-saxon:file:/path/to/transform.xsl?transformerFactoryConfigurationStrategy=#allowFileAccess")
+----
+
+Setting `secureProcessing=false` does not lift this restriction.
+
diff --git a/extensions/xslt-saxon/runtime/src/main/doc/usage.adoc 
b/extensions/xslt-saxon/runtime/src/main/doc/usage.adoc
new file mode 100644
index 00000000000..6d053d5bd07
--- /dev/null
+++ b/extensions/xslt-saxon/runtime/src/main/doc/usage.adoc
@@ -0,0 +1,35 @@
+=== Access to external resources from stylesheets
+
+Since Camel 4.22 (Camel Quarkus 3.39.0), the `xslt-saxon` endpoint sets 
`XMLConstants.ACCESS_EXTERNAL_STYLESHEET` to an empty string on the Saxon 
`TransformerFactory`.
+Stylesheets that read external resources, for example via `collection()` on a 
`file:` URI, then fail with an error such as `URI scheme 'file' has been 
disallowed`.
+
+To allow the `file` scheme, configure the factory with a 
`TransformerFactoryConfigurationStrategy` bean.
+Camel calls the strategy after it applies its own security settings, so only 
the listed schemes are allowed.
+
+[source,java]
+----
+import javax.xml.XMLConstants;
+
+import jakarta.enterprise.inject.Produces;
+import jakarta.inject.Named;
+import jakarta.inject.Singleton;
+import org.apache.camel.component.xslt.TransformerFactoryConfigurationStrategy;
+
+public class XsltSaxonConfig {
+    @Produces
+    @Singleton
+    @Named("allowFileAccess")
+    TransformerFactoryConfigurationStrategy allowFileAccess() {
+        return (factory, endpoint) -> 
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file");
+    }
+}
+----
+
+Reference the bean from the endpoint:
+
+[source,java]
+----
+to("xslt-saxon:file:/path/to/transform.xsl?transformerFactoryConfigurationStrategy=#allowFileAccess")
+----
+
+Setting `secureProcessing=false` does not lift this restriction.
diff --git 
a/integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
 
b/integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonProducers.java
similarity index 61%
copy from 
integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
copy to 
integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonProducers.java
index 0443ef248e6..116fe239b68 100644
--- 
a/integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
+++ 
b/integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonProducers.java
@@ -16,19 +16,21 @@
  */
 package org.apache.camel.quarkus.component.xslt.saxon.it;
 
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import javax.xml.XMLConstants;
 
-@QuarkusTest
-class XsltSaxonTest {
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Produces;
+import jakarta.inject.Named;
+import jakarta.inject.Singleton;
+import org.apache.camel.component.xslt.TransformerFactoryConfigurationStrategy;
 
-    @Test
-    public void loadComponentXsltSaxon() {
-        /* A simple autogenerated test */
-        RestAssured.get("/xslt-saxon/load/component/xslt-saxon")
-                .then()
-                .statusCode(200);
-    }
+@ApplicationScoped
+public class XsltSaxonProducers {
 
+    @Produces
+    @Singleton
+    @Named("allowFileAccess")
+    TransformerFactoryConfigurationStrategy allowFileAccess() {
+        return (factory, endpoint) -> 
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "file");
+    }
 }
diff --git 
a/integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonResource.java
 
b/integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonResource.java
index 5aa4362788e..2104c710bb4 100644
--- 
a/integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonResource.java
+++ 
b/integration-tests/xslt-saxon/src/main/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonResource.java
@@ -16,14 +16,20 @@
  */
 package org.apache.camel.quarkus.component.xslt.saxon.it;
 
+import java.nio.file.Files;
+
 import jakarta.enterprise.context.ApplicationScoped;
 import jakarta.inject.Inject;
 import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
 import jakarta.ws.rs.Path;
 import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
 import jakarta.ws.rs.core.MediaType;
 import jakarta.ws.rs.core.Response;
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ProducerTemplate;
 import org.jboss.logging.Logger;
 
 @Path("/xslt-saxon")
@@ -36,6 +42,9 @@ public class XsltSaxonResource {
     @Inject
     CamelContext context;
 
+    @Inject
+    ProducerTemplate producerTemplate;
+
     @Path("/load/component/xslt-saxon")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
@@ -47,4 +56,36 @@ public class XsltSaxonResource {
         LOG.warnf("Could not load [%s] from the Camel context", 
COMPONENT_XSLT_SAXON);
         return Response.status(500, COMPONENT_XSLT_SAXON + " could not be 
loaded from the Camel context").build();
     }
+
+    @Path("/file-collection")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response fileCollection(@QueryParam("strategy") String strategy, 
String body) throws Exception {
+        // A stylesheet that reads documents from the file system through 
collection() and the file: scheme
+        var dir = Files.createTempDirectory("xslt-saxon");
+        var data = Files.createDirectory(dir.resolve("data"));
+        Files.writeString(data.resolve("greeting.xml"), 
"<greeting>Hello</greeting>");
+        var stylesheet = Files.writeString(dir.resolve("collection.xsl"), """
+                <xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+                    <xsl:output omit-xml-declaration="yes"/>
+                    <xsl:template match="/">
+                        <result><xsl:value-of 
select="concat(collection('%s?select=*.xml')/greeting, ' ', /name)"/></result>
+                    </xsl:template>
+                </xsl:stylesheet>
+                """.formatted(data.toUri()));
+
+        String uri = "xslt-saxon:file:" + stylesheet;
+        if (strategy != null) {
+            uri += "?transformerFactoryConfigurationStrategy=#" + strategy;
+        }
+        try {
+            return Response.ok(producerTemplate.requestBody(uri, body, 
String.class)).build();
+        } catch (CamelExecutionException e) {
+            Throwable cause = e;
+            while (cause.getCause() != null) {
+                cause = cause.getCause();
+            }
+            return Response.serverError().entity(cause.getMessage()).build();
+        }
+    }
 }
diff --git 
a/integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
 
b/integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
index 0443ef248e6..26c52b66ca1 100644
--- 
a/integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
+++ 
b/integration-tests/xslt-saxon/src/test/java/org/apache/camel/quarkus/component/xslt/saxon/it/XsltSaxonTest.java
@@ -20,6 +20,9 @@ import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import org.junit.jupiter.api.Test;
 
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
 @QuarkusTest
 class XsltSaxonTest {
 
@@ -31,4 +34,24 @@ class XsltSaxonTest {
                 .statusCode(200);
     }
 
+    @Test
+    public void fileCollectionDisallowedByDefault() {
+        RestAssured.given()
+                .body("<name>Camel</name>")
+                .post("/xslt-saxon/file-collection")
+                .then()
+                .statusCode(500)
+                .body(containsString("URI scheme 'file' has been disallowed"));
+    }
+
+    @Test
+    public void 
fileCollectionAllowedByTransformerFactoryConfigurationStrategy() {
+        RestAssured.given()
+                .queryParam("strategy", "allowFileAccess")
+                .body("<name>Camel</name>")
+                .post("/xslt-saxon/file-collection")
+                .then()
+                .statusCode(200)
+                .body(is("<result>Hello Camel</result>"));
+    }
 }

Reply via email to