Skip to content

Commit 2ed10c0

Browse files
author
jinsongzhou
committed
[Security] Disable external entity processing in XML upload to prevent XXE
When uploading XML configuration files (e.g. core-site.xml, hdfs-site.xml), the uploaded bytes are parsed by Hadoop's Configuration.addResource(). Although the current classpath includes Woodstox (which does not expand external entities by default), this implicit protection is fragile and can silently break if dependencies change. This patch explicitly disables external entity processing using a hardened XMLInputFactory before delegating to Hadoop Configuration, ensuring XXE protection regardless of the underlying XML parser implementation. Changes: - Pre-validate the XML stream with XMLInputFactory configured to: - IS_SUPPORTING_EXTERNAL_ENTITIES = false - SUPPORT_DTD = false - FEATURE_SECURE_PROCESSING = true - Switch to Configuration(false) to avoid loading default Hadoop configs
1 parent 316f5e8 commit 2ed10c0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/PlatformFileInfoController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.apache.commons.lang.StringUtils;
2828
import org.apache.hadoop.conf.Configuration;
2929

30+
import javax.xml.XMLConstants;
31+
import javax.xml.stream.XMLInputFactory;
32+
3033
import java.io.ByteArrayInputStream;
3134
import java.io.IOException;
3235
import java.io.InputStream;
@@ -52,7 +55,15 @@ public void uploadFile(Context ctx) throws IOException {
5255
// validate xml config
5356
if (name.toLowerCase().endsWith(".xml")) {
5457
try {
55-
Configuration configuration = new Configuration();
58+
// Explicitly disable external entity processing to prevent XXE attacks,
59+
// regardless of the underlying XML parser implementation on the classpath.
60+
XMLInputFactory xif = XMLInputFactory.newInstance();
61+
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
62+
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
63+
xif.setProperty(XMLConstants.FEATURE_SECURE_PROCESSING, true);
64+
xif.createXMLStreamReader(new ByteArrayInputStream(bytes)).close();
65+
66+
Configuration configuration = new Configuration(false);
5667
configuration.addResource(new ByteArrayInputStream(bytes));
5768
configuration.setDeprecatedProperties();
5869
} catch (Exception e) {

0 commit comments

Comments
 (0)