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 @@ -34,6 +34,9 @@
import java.util.HashMap;
import java.util.Map;

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

/** The controller that handles file requests. */
public class PlatformFileInfoController {

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);
xif.createXMLStreamReader(new ByteArrayInputStream(bytes)).close();

Configuration configuration = new Configuration(false);
configuration.addResource(new ByteArrayInputStream(bytes));
configuration.setDeprecatedProperties();
} catch (Exception e) {
Expand Down
Loading