This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new ce05bc1c2ea0 CAMEL-27380: camel-xslt-saxon - apply the allowed
external protocols to unparsed-text(), json-doc() and the other XSLT 3.0
resource functions (#30591)
ce05bc1c2ea0 is described below
commit ce05bc1c2ea0e4cf5ece0c020d953a19a9ae8e49
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 14:09:18 2026 +0100
CAMEL-27380: camel-xslt-saxon - apply the allowed external protocols to
unparsed-text(), json-doc() and the other XSLT 3.0 resource functions (#30591)
Since CAMEL-24451 the runtime document() function honours the transformer
factory's ACCESS_EXTERNAL_STYLESHEET protocols. Saxon reads the resources of
unparsed-text(), unparsed-text-lines(), unparsed-text-available() and
json-doc() through its UnparsedTextURIResolver instead, which resolves
against the unrestricted resolver used for stylesheet compilation, so these
functions still read external file: and http: resources.
XsltSaxonBuilder now installs a resolver that applies the same allowed
protocols before delegating to the resolver Saxon would otherwise use. It is
installed at the first transform on the Saxon configuration and the
controller, so it also covers a transformer reset for reuse and a stylesheet
run with fn:transform(). Stylesheet compilation (xsl:include/xsl:import),
Camel's classpath:, ref: and bean: schemes, and a factory that permits the
protocols (or all) are unaffected. collection() and uri-collection() were
already restricted by Saxon; the tests cover collection() as well.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/catalog/docs/xslt-saxon-component.adoc | 18 +++
.../src/main/docs/xslt-saxon-component.adoc | 18 +++
.../component/xslt/saxon/XsltSaxonBuilder.java | 128 ++++++++++++++++++
...ltSaxonResourceFunctionsExternalAccessTest.java | 148 +++++++++++++++++++++
.../xslt/saxon/resource-functions-data.txt | 1 +
.../xslt/saxon/resource-functions-included.xsl | 26 ++++
.../component/xslt/saxon/resource-functions.xsl | 67 ++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 17 +++
8 files changed, 423 insertions(+)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xslt-saxon-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xslt-saxon-component.adoc
index bf721054871a..85e19b658093 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xslt-saxon-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xslt-saxon-component.adoc
@@ -227,6 +227,24 @@ available:
<xsl:template ...>
----
+[NOTE]
+====
+The `xslt-saxon` endpoint sets `ACCESS_EXTERNAL_DTD` and
`ACCESS_EXTERNAL_STYLESHEET` on the Saxon
+`TransformerFactory` it creates to the empty (deny-all) value. At transform
time, an external `http:`,
+`https:`, `ftp:` or `file:` URI is then refused by `document()` / `doc()`
(since Camel 4.23), by the
+XSLT 3.0 functions `unparsed-text()`, `unparsed-text-lines()`,
`unparsed-text-available()` and
+`json-doc()` (since Camel 4.24), and by `collection()` and `uri-collection()`:
the transform fails (and
+the reason is logged as a warning), and `unparsed-text-available()` returns
`false`. This also applies
+in a stylesheet run with `fn:transform()`, and to a *relative* reference when
the stylesheet itself was
+loaded from `file:`; for a stylesheet loaded from `classpath:` a relative
reference resolves to a
+`classpath:` URI. Camel's internal `classpath:`, `ref:` and `bean:` schemes
remain available to
+`document()`, `unparsed-text()` and `json-doc()`. To permit specific external
protocols, supply your own
+`TransformerFactory` (through the `transformerFactory` option) whose
`ACCESS_EXTERNAL_STYLESHEET`
+allows them: a comma-separated protocol list (such as `file` or `http,https`),
or `all`. A stylesheet's
+`xsl:include` / `xsl:import` references are resolved when the stylesheet is
compiled and are not
+affected by this restriction.
+====
+
=== Spring XML versions
To use the above examples in Spring XML, you would use something like the
following code:
diff --git
a/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
b/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
index bf721054871a..85e19b658093 100644
--- a/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
+++ b/components/camel-xslt-saxon/src/main/docs/xslt-saxon-component.adoc
@@ -227,6 +227,24 @@ available:
<xsl:template ...>
----
+[NOTE]
+====
+The `xslt-saxon` endpoint sets `ACCESS_EXTERNAL_DTD` and
`ACCESS_EXTERNAL_STYLESHEET` on the Saxon
+`TransformerFactory` it creates to the empty (deny-all) value. At transform
time, an external `http:`,
+`https:`, `ftp:` or `file:` URI is then refused by `document()` / `doc()`
(since Camel 4.23), by the
+XSLT 3.0 functions `unparsed-text()`, `unparsed-text-lines()`,
`unparsed-text-available()` and
+`json-doc()` (since Camel 4.24), and by `collection()` and `uri-collection()`:
the transform fails (and
+the reason is logged as a warning), and `unparsed-text-available()` returns
`false`. This also applies
+in a stylesheet run with `fn:transform()`, and to a *relative* reference when
the stylesheet itself was
+loaded from `file:`; for a stylesheet loaded from `classpath:` a relative
reference resolves to a
+`classpath:` URI. Camel's internal `classpath:`, `ref:` and `bean:` schemes
remain available to
+`document()`, `unparsed-text()` and `json-doc()`. To permit specific external
protocols, supply your own
+`TransformerFactory` (through the `transformerFactory` option) whose
`ACCESS_EXTERNAL_STYLESHEET`
+allows them: a comma-separated protocol list (such as `file` or `http,https`),
or `all`. A stylesheet's
+`xsl:include` / `xsl:import` references are resolved when the stylesheet is
compiled and are not
+affected by this restriction.
+====
+
=== Spring XML versions
To use the above examples in Spring XML, you would use something like the
following code:
diff --git
a/components/camel-xslt-saxon/src/main/java/org/apache/camel/component/xslt/saxon/XsltSaxonBuilder.java
b/components/camel-xslt-saxon/src/main/java/org/apache/camel/component/xslt/saxon/XsltSaxonBuilder.java
index e5b2fd193d0f..4a350b481c68 100644
---
a/components/camel-xslt-saxon/src/main/java/org/apache/camel/component/xslt/saxon/XsltSaxonBuilder.java
+++
b/components/camel-xslt-saxon/src/main/java/org/apache/camel/component/xslt/saxon/XsltSaxonBuilder.java
@@ -16,8 +16,12 @@
*/
package org.apache.camel.component.xslt.saxon;
+import java.io.Reader;
import java.io.Writer;
+import java.net.URI;
+import java.util.Locale;
import java.util.Properties;
+import java.util.Set;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
@@ -26,21 +30,40 @@ import
javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stax.StAXSource;
+import net.sf.saxon.Configuration;
+import net.sf.saxon.Controller;
import net.sf.saxon.jaxp.TemplatesImpl;
import net.sf.saxon.jaxp.TransformerImpl;
+import net.sf.saxon.lib.Feature;
import net.sf.saxon.lib.StandardMessageHandler;
+import net.sf.saxon.lib.StandardUnparsedTextResolver;
+import net.sf.saxon.lib.UnparsedTextURIResolver;
import net.sf.saxon.str.UnicodeWriter;
import net.sf.saxon.str.UnicodeWriterToWriter;
+import net.sf.saxon.trans.XPathException;
+import org.apache.camel.Exchange;
import org.apache.camel.component.xslt.XmlSourceHandlerFactoryImpl;
import org.apache.camel.component.xslt.XsltBuilder;
import org.apache.camel.component.xslt.XsltMessageLogger;
+import org.apache.camel.component.xslt.XsltUriResolver;
import org.apache.camel.support.builder.xml.StAX2SAXSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class XsltSaxonBuilder extends XsltBuilder {
+ private static final Logger LOG =
LoggerFactory.getLogger(XsltSaxonBuilder.class);
+
+ // the same protocols XsltUriResolver governs for document(); Camel's
classpath:, ref: and bean: are internal
+ // resource schemes outside the JAXP external-access model and are always
resolved
+ private static final Set<String> EXTERNAL_PROTOCOLS = Set.of("http",
"https", "ftp", "file");
+
private boolean allowStAX = true;
private boolean useJsonBody = false;
private boolean secureProcessing = true;
+ // the external protocols unparsed-text() and json-doc() may read at
transform time, resolved once from the Saxon
+ // configuration as it is fixed once the builder is initialized
+ private volatile ExternalAccess runtimeExternalAccess;
@Override
protected Source prepareSource(Source source) {
@@ -91,6 +114,62 @@ public class XsltSaxonBuilder extends XsltBuilder {
return factory;
}
+ @Override
+ protected void configureTransformer(Transformer transformer, Exchange
exchange) throws Exception {
+ super.configureTransformer(transformer, exchange);
+ if (transformer instanceof TransformerImpl saxonTransformer) {
+
installRuntimeUnparsedTextResolver(saxonTransformer.getUnderlyingController());
+ }
+ }
+
+ /**
+ * Applies the runtime {@code document()} restriction to the XSLT 3.0
functions {@code unparsed-text()},
+ * {@code unparsed-text-lines()}, {@code unparsed-text-available()} and
{@code json-doc()}. Saxon does not read
+ * their resources through the {@link javax.xml.transform.URIResolver}
installed on the transformer, but through its
+ * {@link UnparsedTextURIResolver}, which resolves against the
unrestricted resolver used for stylesheet
+ * compilation. So when Camel's own {@link XsltUriResolver} is in use and
the transformer factory restricts external
+ * stylesheet access, a restricting resolver is installed. It is installed
on the Saxon configuration, as each
+ * controller takes its resolver from there (also when the transformer is
reset for reuse, and for a transformation
+ * started at run time with {@code fn:transform()}), and on the controller
of this transformer, which may have been
+ * created before. This happens at the first transform, after the
stylesheet was compiled; {@code xsl:include} /
+ * {@code xsl:import} are resolved through the {@link
javax.xml.transform.URIResolver} and are unaffected either
+ * way. ({@code collection()} and {@code uri-collection()} are already
restricted by Saxon itself.)
+ */
+ private void installRuntimeUnparsedTextResolver(Controller controller) {
+ if (controller.getUnparsedTextURIResolver() instanceof
RestrictedUnparsedTextResolver
+ || !(getUriResolver() instanceof XsltUriResolver)) {
+ return;
+ }
+ Configuration configuration = controller.getConfiguration();
+ Set<String> allowedExternalProtocols =
resolveRuntimeAllowedExternalProtocols(configuration);
+ if (allowedExternalProtocols == null) {
+ return;
+ }
+ UnparsedTextURIResolver resolver =
configuration.getUnparsedTextURIResolver();
+ if (!(resolver instanceof RestrictedUnparsedTextResolver)) {
+ resolver = new RestrictedUnparsedTextResolver(
+ resolver != null ? resolver : new
StandardUnparsedTextResolver(), allowedExternalProtocols);
+ configuration.setUnparsedTextURIResolver(resolver);
+ }
+ controller.setUnparsedTextURIResolver(resolver);
+ }
+
+ /**
+ * Reads the external protocols the runtime resolver may load. Saxon keeps
the factory's
+ * {@code ACCESS_EXTERNAL_STYLESHEET} attribute as its {@link
Feature#ALLOWED_PROTOCOLS} configuration property,
+ * which is what the factory's {@code getAttribute} returns. Returns
{@code null} (unrestricted) when it is
+ * {@code "all"}, which is also the Saxon default when the attribute is
not set.
+ */
+ private Set<String> resolveRuntimeAllowedExternalProtocols(Configuration
configuration) {
+ ExternalAccess access = runtimeExternalAccess;
+ if (access == null) {
+ String value =
configuration.getConfigurationProperty(Feature.ALLOWED_PROTOCOLS);
+ access = new
ExternalAccess(XsltUriResolver.parseAllowedProtocols(value));
+ runtimeExternalAccess = access;
+ }
+ return access.allowedProtocols();
+ }
+
@Override
protected Templates createTemplates(TransformerFactory factory, Source
source) throws TransformerConfigurationException {
final Templates templates = super.createTemplates(factory, source);
@@ -100,6 +179,55 @@ public class XsltSaxonBuilder extends XsltBuilder {
return templates;
}
+ /**
+ * The resolved runtime external access; {@code allowedProtocols} is
{@code null} when external access is
+ * unrestricted.
+ */
+ private record ExternalAccess(Set<String> allowedProtocols) {
+ }
+
+ /**
+ * Enforces the {@code ACCESS_EXTERNAL_STYLESHEET} restriction for the
resources Saxon reads through its
+ * {@link UnparsedTextURIResolver} ({@code unparsed-text()}, {@code
unparsed-text-lines()},
+ * {@code unparsed-text-available()} and {@code json-doc()}), the same way
{@link XsltUriResolver} does for
+ * {@code document()}: a forbidden external protocol throws an {@link
XPathException}, so the function fails (or
+ * {@code unparsed-text-available()} returns false) instead of reading the
resource. Only the standard external
+ * protocols are governed; Camel's {@code classpath:}, {@code ref:} and
{@code bean:} schemes are passed to the
+ * delegate resolver, as are the allowed protocols.
+ */
+ static final class RestrictedUnparsedTextResolver implements
UnparsedTextURIResolver {
+
+ private final UnparsedTextURIResolver delegate;
+ private final Set<String> allowedExternalProtocols;
+
+ RestrictedUnparsedTextResolver(UnparsedTextURIResolver delegate,
Set<String> allowedExternalProtocols) {
+ this.delegate = delegate;
+ this.allowedExternalProtocols = allowedExternalProtocols;
+ }
+
+ @Override
+ public Reader resolve(URI absoluteURI, String encoding, Configuration
config, boolean fallback)
+ throws XPathException {
+ String scheme = absoluteURI.getScheme();
+ // compare case-insensitively so an upper/mixed-case scheme cannot
slip past the guard
+ String protocol = scheme != null ? scheme.toLowerCase(Locale.ROOT)
: null;
+ if (protocol != null && EXTERNAL_PROTOCOLS.contains(protocol) &&
!allowedExternalProtocols.contains(protocol)) {
+ // log the denial explicitly: unparsed-text-available() turns
this exception into false, so this WARN
+ // is what actually tells an operator why the function did not
read the resource
+ LOG.warn("Refusing to resolve external resource {} for the
XSLT unparsed-text() or json-doc() function:"
+ + " protocol '{}' is not permitted by the transformer
factory's ACCESS_EXTERNAL_STYLESHEET"
+ + " restriction",
+ absoluteURI, protocol);
+ throw new XPathException(
+ "Refusing to resolve external resource " + absoluteURI
+ + " for the XSLT unparsed-text() or
json-doc() function: protocol '" + protocol
+ + "' is not permitted by the
transformer factory's ACCESS_EXTERNAL_STYLESHEET restriction",
+ "FOUT1170");
+ }
+ return delegate.resolve(absoluteURI, encoding, config, fallback);
+ }
+ }
+
private static class MessageConsumerWriter extends Writer {
private final XsltMessageLogger xsltMessageLogger;
diff --git
a/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/saxon/XsltSaxonResourceFunctionsExternalAccessTest.java
b/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/saxon/XsltSaxonResourceFunctionsExternalAccessTest.java
new file mode 100644
index 000000000000..630269b40068
--- /dev/null
+++
b/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/saxon/XsltSaxonResourceFunctionsExternalAccessTest.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.xslt.saxon;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+
+import net.sf.saxon.TransformerFactoryImpl;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The XSLT 3.0 resource functions {@code unparsed-text()}, {@code
unparsed-text-lines()},
+ * {@code unparsed-text-available()}, {@code json-doc()} and {@code
collection()} honour the transformer factory's
+ * {@code ACCESS_EXTERNAL_STYLESHEET} restriction at transform time, the same
way {@code document()} does, also in a
+ * stylesheet run with {@code fn:transform()}. The {@code xslt-saxon} endpoint
sets it to deny-all, so an external
+ * {@code file:} resource is refused by default; a factory that permits {@code
file} (or {@code all}) lets it through
+ * again. The stylesheet's classpath {@code xsl:include} and Camel's {@code
classpath:} scheme keep working.
+ */
+public class XsltSaxonResourceFunctionsExternalAccessTest extends
CamelTestSupport {
+
+ private static final String XSL =
"org/apache/camel/component/xslt/saxon/resource-functions.xsl";
+ private static final String MARKER = "EXTERNAL-DATA";
+
+ @TempDir
+ Path dir;
+
+ @BeforeEach
+ void createExternalResources() throws Exception {
+ Files.writeString(dir.resolve("data.txt"), MARKER + "\n");
+ Files.writeString(dir.resolve("data.json"), "{\"marker\": \"" + MARKER
+ "\"}");
+ Path collection = Files.createDirectories(dir.resolve("collection"));
+ Files.writeString(collection.resolve("data.xml"), "<data><marker>" +
MARKER + "</marker></data>");
+ }
+
+ @Override
+ protected void bindToRegistry(Registry registry) {
+ registry.bind("fileFactory", factoryAllowing("file"));
+ registry.bind("allFactory", factoryAllowing("all"));
+ }
+
+ private static TransformerFactoryImpl factoryAllowing(String protocols) {
+ TransformerFactoryImpl factory = new TransformerFactoryImpl();
+ factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
protocols);
+ return factory;
+ }
+
+ private String uriOf(String function) {
+ return switch (function) {
+ case "json-doc" -> dir.resolve("data.json").toUri().toString();
+ case "collection" -> dir.resolve("collection").toUri().toString();
+ default -> dir.resolve("data.txt").toUri().toString();
+ };
+ }
+
+ private String transform(String endpoint, String function, String
resourceUri) {
+ return template.requestBodyAndHeaders(endpoint, "<a/>",
+ Map.of("function", function, "resourceUri", resourceUri),
String.class);
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "unparsed-text", "unparsed-text-lines",
"json-doc", "collection", "transform" })
+ public void externalFileIsRefusedByDefault(String function) {
+ String uri = uriOf(function);
+ // the endpoint's factory denies external access ("" == deny-all), so
the function fails instead of reading the
+ // (existing) file given by a message header
+ assertThrows(CamelExecutionException.class, () ->
transform("direct:default", function, uri));
+ }
+
+ @Test
+ public void unparsedTextAvailableIsFalseByDefault() {
+ assertEquals("included:false", transform("direct:default",
"unparsed-text-available", uriOf("unparsed-text")));
+ }
+
+ @Test
+ public void refusalNamesTheRestriction() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> transform("direct:default", "unparsed-text",
uriOf("unparsed-text")));
+ assertTrue(messages(e).contains("ACCESS_EXTERNAL_STYLESHEET"),
+ "expected the refusal to name the restriction, got: " +
messages(e));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "direct:file", "direct:all" })
+ public void externalFileIsReadWhenTheFactoryPermitsIt(String endpoint) {
+ assertEquals("included:" + MARKER + "\n", transform(endpoint,
"unparsed-text", uriOf("unparsed-text")));
+ assertEquals("included:" + MARKER, transform(endpoint,
"unparsed-text-lines", uriOf("unparsed-text")));
+ assertEquals("included:true", transform(endpoint,
"unparsed-text-available", uriOf("unparsed-text")));
+ assertEquals("included:" + MARKER, transform(endpoint, "json-doc",
uriOf("json-doc")));
+ assertEquals("included:" + MARKER, transform(endpoint, "collection",
uriOf("collection")));
+ assertEquals("included:" + MARKER + "\n", transform(endpoint,
"transform", uriOf("unparsed-text")));
+ }
+
+ @Test
+ public void classpathResourceIsReadByDefault() {
+ // Camel's classpath: scheme is outside the JAXP external-access model
and is resolved as before
+ assertEquals("included:CLASSPATH-DATA\n", transform("direct:default",
"unparsed-text",
+
"classpath:org/apache/camel/component/xslt/saxon/resource-functions-data.txt"));
+ }
+
+ private static String messages(Throwable e) {
+ StringBuilder sb = new StringBuilder();
+ for (Throwable t = e; t != null; t = t.getCause()) {
+ sb.append(t.getMessage()).append('\n');
+ }
+ return sb.toString();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:default").to("xslt-saxon:" + XSL);
+ from("direct:file").to("xslt-saxon:" + XSL +
"?transformerFactory=#fileFactory");
+ from("direct:all").to("xslt-saxon:" + XSL +
"?transformerFactory=#allFactory");
+ }
+ };
+ }
+}
diff --git
a/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions-data.txt
b/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions-data.txt
new file mode 100644
index 000000000000..7138467af8cc
--- /dev/null
+++
b/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions-data.txt
@@ -0,0 +1 @@
+CLASSPATH-DATA
diff --git
a/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions-included.xsl
b/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions-included.xsl
new file mode 100644
index 000000000000..0780224ee9a5
--- /dev/null
+++
b/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions-included.xsl
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:template name="prefix">
+ <xsl:text>included:</xsl:text>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git
a/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions.xsl
b/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions.xsl
new file mode 100644
index 000000000000..3e46ace01fdb
--- /dev/null
+++
b/components/camel-xslt-saxon/src/test/resources/org/apache/camel/component/xslt/saxon/resource-functions.xsl
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!-- Reads the resource given by the resourceUri parameter with the XSLT 3.0
function given by the function parameter. -->
+<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:output method="text"/>
+
+ <xsl:param name="function"/>
+ <xsl:param name="resourceUri"/>
+
+ <!-- A stylesheet run with fn:transform() that reads the resource given by
its u parameter with unparsed-text(). -->
+ <xsl:variable name="child" as="xs:string"
xmlns:xs="http://www.w3.org/2001/XMLSchema"><![CDATA[
+ <xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:param name="u"/>
+ <xsl:template name="xsl:initial-template">
+ <out><xsl:value-of select="unparsed-text($u)"/></out>
+ </xsl:template>
+ </xsl:stylesheet>]]></xsl:variable>
+
+ <!-- A classpath include, resolved relative to this stylesheet by Camel's
URI resolver when it is compiled. -->
+ <xsl:include href="resource-functions-included.xsl"/>
+
+ <xsl:template match="/">
+ <xsl:call-template name="prefix"/>
+ <xsl:choose>
+ <xsl:when test="$function = 'unparsed-text'">
+ <xsl:value-of select="unparsed-text($resourceUri)"/>
+ </xsl:when>
+ <xsl:when test="$function = 'unparsed-text-lines'">
+ <xsl:value-of select="unparsed-text-lines($resourceUri)"/>
+ </xsl:when>
+ <xsl:when test="$function = 'unparsed-text-available'">
+ <xsl:value-of select="unparsed-text-available($resourceUri)"/>
+ </xsl:when>
+ <xsl:when test="$function = 'json-doc'">
+ <xsl:value-of select="json-doc($resourceUri)?marker"/>
+ </xsl:when>
+ <xsl:when test="$function = 'collection'">
+ <xsl:value-of select="collection($resourceUri)//marker"/>
+ </xsl:when>
+ <xsl:when test="$function = 'transform'">
+ <xsl:value-of select="transform(map {
+ 'stylesheet-text': $child,
+ 'initial-template':
QName('http://www.w3.org/1999/XSL/Transform', 'initial-template'),
+ 'stylesheet-params': map { QName('', 'u'):
$resourceUri } })?output"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 239e70c01277..299a87218c03 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -5341,6 +5341,23 @@ a Saxon PE/EE stylesheet can call Java extension
functions) also restores the pr
`Source` parsing: `setTransformerFactory(...)` replaces the factory, but the
strategy's `XsltSaxonBuilder` keeps
`secureProcessing=true`, so the body is still parsed with the restricted
reader.
+=== camel-xslt-saxon - unparsed-text() and json-doc() honour the same
restriction as document()
+
+Since Camel 4.23 the `document()` function refuses an external `http:`,
`https:`, `ftp:` or `file:` URI at
+transform time unless the transformer factory's `ACCESS_EXTERNAL_STYLESHEET`
permits the protocol; the
+`xslt-saxon` endpoint sets it to the empty (deny-all) value. Saxon does not
read the resources of the XSLT 3.0
+functions `unparsed-text()`, `unparsed-text-lines()`,
`unparsed-text-available()` and `json-doc()` through the
+resolver installed on the transformer, so these functions still read such a
URI. They now honour the same
+restriction as `document()`, also in a stylesheet run with `fn:transform()`: a
refused URI fails the transform (and
+the reason is logged as a warning), and `unparsed-text-available()` returns
`false`. As with `document()`, this
+includes a relative URI when the stylesheet was loaded from `file:`.
(`collection()` and `uri-collection()` were
+already restricted by Saxon.)
+
+Camel's `classpath:`, `ref:` and `bean:` schemes are not affected, nor are
`xsl:include` and `xsl:import`. A route
+that needs these functions to read an external resource supplies a
`TransformerFactory` through the
+`transformerFactory` option whose `ACCESS_EXTERNAL_STYLESHEET` permits the
protocols (a comma-separated list such
+as `file` or `http,https`, or `all`).
+
=== camel-ical - each unmarshal parses with its own calendar builder
The `ical` data format used one ical4j `CalendarBuilder` for all exchanges.
Two exchanges that were unmarshalled at