-
Notifications
You must be signed in to change notification settings - Fork 383
[Security] Disable external entity processing in XML upload to prevent XXE #4119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| xif.createXMLStreamReader(new ByteArrayInputStream(bytes)).close(); | ||
|
|
||
| Configuration configuration = new Configuration(false); | ||
| configuration.addResource(new ByteArrayInputStream(bytes)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FEATURE_SECURE_PROCESSINGis not a standard property ofXMLInputFactoryand may throw an exception.