From 05472fab99a8430c20be0a018a7a09e04f7f29b6 Mon Sep 17 00:00:00 2001 From: Yogi Kortisa Date: Fri, 16 Oct 2026 09:16:58 +0700 Subject: [PATCH] fix(xml): prevent XXE in xml.xpath (disable DTD + external entities) XmlModule.compile() (the Starlark xml.xpath function) parsed the provided XML content with a default DocumentBuilderFactory, which resolves DTDs and external entities. When the content originates from an untrusted source (e.g. a file in a migrated repository), a document such as: ]> enables XML External Entity (XXE) attacks: local file disclosure, SSRF, and denial of service via entity expansion. Disable DTD processing (disallow-doctype-decl), XInclude, and entity-reference expansion before building the parser. --- java/com/google/copybara/xml/XmlModule.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/com/google/copybara/xml/XmlModule.java b/java/com/google/copybara/xml/XmlModule.java index dd47385dd..ddfd785c0 100644 --- a/java/com/google/copybara/xml/XmlModule.java +++ b/java/com/google/copybara/xml/XmlModule.java @@ -55,6 +55,12 @@ public Object compile(String xmlContent, String expression, String type) DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { + // Prevent XML External Entity (XXE) processing: reject DTDs (which also + // disables entity resolution) and external entities, since the parsed XML + // content may come from an untrusted source (e.g. a migrated repository). + builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + builderFactory.setXIncludeAware(false); + builderFactory.setExpandEntityReferences(false); builder = builderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new RuntimeException("Error creating document builder for parsing XML");