ppkarwasz commented on code in PR #11250:
URL: https://github.com/apache/seatunnel/pull/11250#discussion_r3709492015


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/XmlReadStrategy.java:
##########
@@ -169,6 +190,29 @@ public void readProcess(
                         });
     }
 
+    /**
+     * Configure the XML reader with XXE-safe defaults before parsing 
user-controlled file contents.
+     */
+    private SAXReader createSecureSaxReader() {
+        SAXReader saxReader = new SAXReader();
+        try {
+            // Keep JAXP entity-expansion limits enabled even if Xerces is on 
the classpath.
+            saxReader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+            saxReader.setFeature(DISALLOW_DOCTYPE_DECL, true);
+            saxReader.setFeature(EXTERNAL_GENERAL_ENTITIES, false);
+            saxReader.setFeature(EXTERNAL_PARAMETER_ENTITIES, false);
+            saxReader.setFeature(LOAD_EXTERNAL_DTD, false);
+            saxReader.setEntityResolver(
+                    (publicId, systemId) -> new InputSource(new 
StringReader("")));

Review Comment:
   All these properties are a little bit of an overkill and disable external 
subsets and entities three times:
   
   1. `DISALLOW_DOCTYPE_DECL` requires a Xerces-alike parser and it throws on 
any `DOCTYPE` declaration,
   2. `EXTERNAL_*_ENTITIES/LOAD_EXTERNAL_DTD` also requires Xerces-alike 
parsers, but leniently ignores external fetches,
   3. the `setEntityResolver` has the **same** effect as any of the other two 
groups, but does not require a Xerces-alike parser.



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