oscerd commented on code in PR #28160:
URL: https://github.com/apache/camel/pull/28160#discussion_r4386437342


##########
components/camel-xslt-saxon/src/main/java/org/apache/camel/component/xslt/saxon/XsltSaxonHelper.java:
##########
@@ -20,20 +20,55 @@
 import java.util.Map;
 
 import javax.xml.XMLConstants;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
 
 import net.sf.saxon.Configuration;
 import net.sf.saxon.TransformerFactoryImpl;
 import net.sf.saxon.lib.ExtensionFunctionDefinition;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.converter.jaxp.XMLReaderPool;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 final class XsltSaxonHelper {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(XsltSaxonHelper.class);
 
+    private static final String EXTERNAL_GENERAL_ENTITIES = 
"http://xml.org/sax/features/external-general-entities";;
+    private static final String EXTERNAL_PARAMETER_ENTITIES = 
"http://xml.org/sax/features/external-parameter-entities";;
+    private static final String LOAD_EXTERNAL_DTD = 
"http://apache.org/xml/features/nonvalidating/load-external-dtd";;
+
+    // Configured once: a SAXParserFactory on the classpath that does not 
recognise one of the required features fails
+    // here, on the first use of this class, rather than silently degrading on 
every exchange. The pool hands out a
+    // reader for a single parse and is safe to share between threads.
+    private static final XMLReaderPool SECURE_XML_READER_POOL = new 
XMLReaderPool(createSecureSaxParserFactory());

Review Comment:
   Implemented in 7d841f8. The pool is now initialized lazily via 
`SecureReaderPoolHolder`, preventing class initialization failures if the 
parser cannot be built for routes that intentionally set 
`secureProcessing=false`. Also added 
`testStreamSourceUnwrappedWhenSecureProcessingDisabled` to 
`XsltSaxonDomSourceTest` to verify that `secureProcessing=false` passes 
`StreamSource` through unwrapped.
   
   _Claude Code on behalf of oscerd_



##########
components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/saxon/XsltSaxonHelperConfigurationTest.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.io.ByteArrayInputStream;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+
+import net.sf.saxon.TransformerFactoryImpl;
+import org.apache.camel.util.xml.StringSource;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unit tests for the configuration helpers shared by {@link 
XsltSaxonEndpoint} and
+ * {@link XsltSaxonAggregationStrategy}.
+ */
+class XsltSaxonHelperConfigurationTest {
+
+    @Test
+    void shouldRestrictExternalResourceAccessOnFactory() {
+        TransformerFactoryImpl factory = new TransformerFactoryImpl();
+        XsltSaxonHelper.configureExternalAccess(factory);
+
+        assertEquals("", 
factory.getAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET));
+    }

Review Comment:
   Saxon's `SaxonTransformerFactory` does not support reading 
`ACCESS_EXTERNAL_DTD` via `getAttribute(...)` and throws 
`IllegalArgumentException: Unknown configuration property ... 
http://javax.xml.XMLConstants/property/accessExternalDTD` (which is why 
`XsltSaxonHelper.configureExternalAccess` catches `IllegalArgumentException` on 
`setAttribute`). Hence this attribute cannot be asserted on 
`TransformerFactoryImpl`.
   
   _Claude Code on behalf of oscerd_



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