Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;

import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -52,7 +55,15 @@ public void uploadFile(Context ctx) throws IOException {
// validate xml config
if (name.toLowerCase().endsWith(".xml")) {
try {
Configuration configuration = new Configuration();
// Explicitly disable external entity processing to prevent XXE attacks,
// regardless of the underlying XML parser implementation on the classpath.
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xif.setProperty(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FEATURE_SECURE_PROCESSING is not a standard property of XMLInputFactory and may throw an exception.

xif.createXMLStreamReader(new ByteArrayInputStream(bytes)).close();

Configuration configuration = new Configuration(false);
configuration.addResource(new ByteArrayInputStream(bytes));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XXE fix is still incomplete. The new XMLInputFactory parse only acts as a pre-check, but the actual validation still happens in Configuration.addResource(new ByteArrayInputStream(bytes)). In Hadoop 3.4.0, this overload does not use the restricted parser path by default, so the XML is reparsed in a way that can still allow DTD / external entity processing. In other words, this adds an extra parse, but it does not fully close the XXE risk.

configuration.setDeprecatedProperties();
} catch (Exception e) {
Expand Down
Loading