Repository navigation
fix(xml): prevent XXE in xml.xpath (disable DTD + external entities) - #357
Open
yogikortisa wants to merge 1 commit into
Open
yogikortisa wants to merge 1 commit into
yogikortisa wants to merge 1 commit into
Conversation
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: <!DOCTYPE x [<!ENTITY e SYSTEM "file:///etc/passwd">]> 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.
There was a problem hiding this comment.
Code Review
This pull request updates the XmlModule.java file to secure the XML parser against XML External Entity (XXE) injection. It configures the DocumentBuilderFactory to disallow doctype declarations, disable XInclude, and disable expanding entity references. No review comments were provided, so there is no feedback to address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
XmlModule.compile()— the Starlarkxml.xpath(content, expression, type)function — parses the providedcontentwith a defaultDocumentBuilderFactory:A default
DocumentBuilderFactoryresolves DTDs and external entities. When the XML content comes from an untrusted source — for example a file read from a repository being migrated — a document such as:enables XML External Entity (XXE) attacks on the host running Copybara: local file disclosure, server-side request forgery (
http://…entities), and denial of service via entity expansion.Fix
Disable DTD processing (
disallow-doctype-decl, which also blocks entity resolution), XInclude, and entity-reference expansion before constructing the parser. XPath over normal XML content is unaffected.