You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by "snoopdave (via GitHub)" <gi...@apache.org> on 2026/10/02 22:25:41 UTC

[PR] Adopt Apache Commons Secure XML for XML parsing [roller]

snoopdave opened a new pull request, #201:
URL: https://github.com/apache/roller/pull/201

   ## Summary
   
   Roller configured its XML parsers by hand in two places, with two separate feature lists:
   
   - `SafeSAXBuilder`, used for JDOM parsing (bookmark import, theme metadata, runtime config definitions, menus).
   - `WebloggerImpl`, which set features on the XML-RPC library's shared `SAXParserFactory`. If the parser did not accept a setting, it logged an error and continued.
   
   This PR moves both onto [Apache Commons Secure XML](https://commons.apache.org/proper/commons-secure-xml/) 1.0.0:
   
   - **New `SecureXmlParsers`** returns a namespace-aware, non-validating `SAXParserFactory` from `SecureSAXParserFactory.newNSInstance()`, and refuses document type declarations on top, as Roller did before. It throws if the configuration cannot be applied.
   - **`SafeSAXBuilder`** now gets its readers from `SecureXmlParsers`. It keeps its existing settings as an overlapping layer, so all its call sites are unchanged.
   - **`WebloggerImpl`** installs the same factory for XML-RPC with `SAXParsers.setSAXParserFactory(...)`. Startup now fails instead of continuing with an unconfigured parser.
   
   The new dependency has no runtime dependencies of its own, and its NOTICE is the standard ASF one, so the release LICENSE and NOTICE files are unchanged.
   
   ## Testing
   
   - New `SecureXmlParsersTest` (5) and two new `SafeSAXBuilderTest` cases: ordinary namespaced documents parse, document type declarations are refused, declared external entities are not read, and the XML-RPC library uses the same configuration.
   - `mvn -pl app test` on JDK 11: 332 tests, 0 failures, 1 skipped. The suite starts Roller, so the XML-RPC installation runs during it.
   - `roller.war` bundles `commons-secure-xml-1.0.0.jar`.
   
   Targets `roller-6.1.x` for 6.1.7. A matching change for `master` will follow.
   


-- 
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: dev-unsubscribe@roller.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Adopt Apache Commons Secure XML for XML parsing [roller]

Posted by "snoopdave (via GitHub)" <gi...@apache.org>.
snoopdave commented on PR #201:
URL: https://github.com/apache/roller/pull/201#issuecomment-5973463400

   🐞Claude Issue: **PR-Review: General Issues**
   
   The following issues were found but cannot be attached to a specific line in the diff:
   
   - **Blocking:** `CHANGES.md` on `roller-6.1.x` is not updated. Add a 6.1.7 entry: XML parsing now uses Apache Commons Secure XML 1.0.0 (new bundled dependency), and Roller now fails at startup instead of logging an error when the XML-RPC parser cannot be configured. Operators should know about that behaviour change.
   - **Important:** No CI runs on this PR, because the `roller-6.1.x` workflows trigger only for `master`. I ran `SecureXmlParsersTest` (5) and `SafeSAXBuilderTest` (4) locally on JDK 11: all pass. I also confirmed that `commons-secure-xml` 1.0.0 is on Maven Central with a Java 8 target, and that no other `*Factory.newInstance()` parser construction remains in `app/src/main/java`.


-- 
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: dev-unsubscribe@roller.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Adopt Apache Commons Secure XML for XML parsing [roller]

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #201:
URL: https://github.com/apache/roller/pull/201#discussion_r4181781498


##########
app/src/main/java/org/apache/roller/weblogger/util/SecureXmlParsers.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.util;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.commons.xml.secure.SecureSAXParserFactory;
+import org.apache.xmlrpc.util.SAXParsers;
+import org.jdom2.JDOMException;
+import org.jdom2.input.sax.XMLReaderJDOMFactory;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * The XML parser configuration Roller uses for every document it parses itself.
+ *
+ * <p>Parsers come from Apache Commons Secure XML, which configures the JAXP
+ * implementation so that nothing a document names is resolved, and throws
+ * rather than continuing if a setting cannot be applied. On top of that,
+ * Roller refuses any document type declaration: none of the documents Roller
+ * reads needs one.
+ */
+public final class SecureXmlParsers {
+
+    /** Xerces feature name, honoured by the JDK's own parser. */
+    static final String DISALLOW_DOCTYPE =
+            "http://apache.org/xml/features/disallow-doctype-decl";
+
+    /** Supplies JDOM with readers from {@link #newSAXParserFactory()}. */
+    public static final XMLReaderJDOMFactory JDOM_READERS = new XMLReaderJDOMFactory() {
+        @Override
+        public XMLReader createXMLReader() throws JDOMException {
+            try {
+                return newSAXParserFactory().newSAXParser().getXMLReader();

Review Comment:
   The new `1.1.0` version of Commons Secure XML, which is already under vote and will be released today, introduces `SecureSAXParserFactory.newNSXMLReader()`.



##########
app/src/main/java/org/apache/roller/weblogger/util/SecureXmlParsers.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.util;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.commons.xml.secure.SecureSAXParserFactory;
+import org.apache.xmlrpc.util.SAXParsers;
+import org.jdom2.JDOMException;
+import org.jdom2.input.sax.XMLReaderJDOMFactory;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * The XML parser configuration Roller uses for every document it parses itself.
+ *
+ * <p>Parsers come from Apache Commons Secure XML, which configures the JAXP
+ * implementation so that nothing a document names is resolved, and throws
+ * rather than continuing if a setting cannot be applied. On top of that,
+ * Roller refuses any document type declaration: none of the documents Roller
+ * reads needs one.
+ */
+public final class SecureXmlParsers {
+
+    /** Xerces feature name, honoured by the JDK's own parser. */
+    static final String DISALLOW_DOCTYPE =
+            "http://apache.org/xml/features/disallow-doctype-decl";
+
+    /** Supplies JDOM with readers from {@link #newSAXParserFactory()}. */
+    public static final XMLReaderJDOMFactory JDOM_READERS = new XMLReaderJDOMFactory() {
+        @Override
+        public XMLReader createXMLReader() throws JDOMException {
+            try {
+                return newSAXParserFactory().newSAXParser().getXMLReader();
+            } catch (ParserConfigurationException | SAXException e) {
+                throw new JDOMException("Could not create an XML reader", e);
+            }
+        }
+
+        @Override
+        public boolean isValidating() {
+            return false;
+        }
+    };
+
+    private SecureXmlParsers() {
+    }
+
+    /**
+     * Returns a namespace-aware, non-validating SAX parser factory that
+     * resolves nothing a document names and refuses document type
+     * declarations.
+     *
+     * @throws IllegalStateException if the configuration cannot be applied
+     */
+    public static SAXParserFactory newSAXParserFactory() {
+        SAXParserFactory factory = SecureSAXParserFactory.newNSInstance();
+        factory.setValidating(false);
+        try {
+            factory.setFeature(DISALLOW_DOCTYPE, true);
+        } catch (ParserConfigurationException | SAXException e) {
+            throw new IllegalStateException(
+                    "The XML parser does not support refusing document type declarations", e);
+        }

Review Comment:
   If https://github.com/apache/roller/pull/198#discussion_r4181617672 is implemented, I don't think there is a compelling reason to disable `DOCTYPE`. As far as I know, only SOAP and XMPP explicitly ban `DOCTYPE` declarations.



-- 
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: dev-unsubscribe@roller.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Adopt Apache Commons Secure XML for XML parsing [roller]

Posted by "snoopdave (via GitHub)" <gi...@apache.org>.
snoopdave commented on PR #201:
URL: https://github.com/apache/roller/pull/201#issuecomment-5979824302

   🤖Claude: 
   - **CHANGES.md:** fixed by adding a 6.1.7 section (not yet pushed). It names the new bundled dependency (`commons-secure-xml` 1.0.0) and the startup change: Roller now stops at startup when the XML-RPC parser cannot be configured, where it used to log an error and continue.
   - **CI:** not fixed here. #206 has since added `roller-6.1.x` to the CI and CodeQL triggers; checks will start after this PR is rebased onto `roller-6.1.x`.


-- 
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: dev-unsubscribe@roller.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Adopt Apache Commons Secure XML for XML parsing [roller]

Posted by "snoopdave (via GitHub)" <gi...@apache.org>.
snoopdave merged PR #201:
URL: https://github.com/apache/roller/pull/201


-- 
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: dev-unsubscribe@roller.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Adopt Apache Commons Secure XML for XML parsing [roller]

Posted by "snoopdave (via GitHub)" <gi...@apache.org>.
snoopdave commented on PR #201:
URL: https://github.com/apache/roller/pull/201#issuecomment-5981387934

   Manually tested on the 6.1.7 integration build (Tomcat 9, JDK 11, MySQL 8). Pass.
   
   - Startup logs no parser configuration errors, and the WAR bundles `commons-secure-xml-1.0.0.jar`.
   - OPML bookmark import works for a plain file. Files with an external entity or an external DTD are refused ("XML document type declarations are not supported"), no blogroll is created, and a local listener received no requests.
   - XML-RPC `blogger.getUsersBlogs` works. Requests with an external entity or DTD return a fault, and nothing is fetched.
   - Theme switching and Admin → Configuration load normally.
   


-- 
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: dev-unsubscribe@roller.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org