disable dtd and external entities in stax xml parsers#12251
Open
jmestwa-coder wants to merge 1 commit into
Open
disable dtd and external entities in stax xml parsers#12251jmestwa-coder wants to merge 1 commit into
jmestwa-coder wants to merge 1 commit into
Conversation
hand-written XMLInputFactory readers resolved external entities, allowing xxe and ssrf from downloaded poms, extension and plugin descriptors
2 tasks
gnodet
reviewed
Jun 13, 2026
gnodet
left a comment
Contributor
There was a problem hiding this comment.
Thanks for raising this — the XXE hardening is a good idea.
A few observations:
- Duplication: the PR copies an identical
newInputFactory()helper into 5 separate classes. A single shared method would be easier to maintain. - Missing coverage: the Velocity templates (
reader-stax.vm,reader.vm) that generate StAX readers for settings.xml, toolchains.xml, plugin.xml, metadata.xml, etc. also create their ownXMLInputFactoryinstances and are not hardened by this PR. - Context: external entity / XInclude support was an intentional feature (MNG-5862) that was later extracted into maven-xinclude-extension. That extension creates its own factory with entities enabled under a restricted resolver, so it is unaffected by this hardening.
I've opened #12256 as an alternative that centralizes the factory creation into XmlService.newXMLInputFactory() and also covers the Velocity templates.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
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.
XXE via external entity resolution in the StAX XML parsers
Maven's hand-written StAX readers build their parser with
XMLInputFactory.newFactory(), and the Woodstox defaults resolve external entities. Apom.xml,META-INF/maven/extension.xmlorplugin.xmlread from a downloaded artifact can pull infile://orhttp://SYSTEM entities, which gives local file disclosure and SSRF while a build runs.SUPPORT_DTDandIS_SUPPORTING_EXTERNAL_ENTITIESare now turned off on every input factory used to read XML. None of Maven's own formats carry a DOCTYPE, so this only rejects hostile input.The added test in
ExtensionDescriptorBuilderTestleaks a temp file through an external entity in an extension descriptor; it fails on the current tree and passes with the factories hardened.Your pull request should address just one issue, without pulling in other changes.
Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
Each commit in the pull request should have a meaningful subject line and body.
Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
Run
mvn verifyto make sure basic checks pass.You have run the Core IT successfully.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.