Skip to content

Keep XMLUnit from re-parsing documents with an unhardened parser - #110

Merged
garydgregory merged 2 commits into
apache:masterfrom
ppkarwasz:fix/xmlunit-secure-diff
Sep 17, 2026
Merged

garydgregory merged 2 commits into
apache:masterfrom
ppkarwasz:fix/xmlunit-secure-diff

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

<xu:assertDocumentsEqual> fed the XML text of both dom4j documents to XMLUnit's Diff, which re-parses it with XMLUnit's own JAXP DocumentBuilder. That parser fetches the external DTD of any document with a DOCTYPE, regardless of how the documents were read in the first place.

The tag now builds the two DOM trees itself with a DocumentBuilder from Commons Secure XML and hands those to Diff(Document, Document), so no external entity is fetched on the comparison path either. The ignoreWhitespace attribute still reaches the builder, as it did through XMLUnit's global setting, and XMLUnit's whitespace stripping keeps working on the trees it receives.

A regression test compares an in-memory document whose DOCTYPE points to a DTD that does not exist, with and without ignoreWhitespace, since the latter routes the trees through XMLUnit's whitespace-stripping transform. Both cases fail on master and pass with this change.

Independent of the dom4j 2.1.5 / SAXReader pull request; together they close both external-fetch paths of the xmlunit tag library.

🤖 Generated with Claude Code

ppkarwasz and others added 2 commits September 17, 2026 23:01
`<xu:assertDocumentsEqual>` fed the XML text of both dom4j documents to
XMLUnit's `Diff`, which re-parses it with XMLUnit's own JAXP
DocumentBuilder. That parser fetches the external DTD of any document
with a DOCTYPE, regardless of how the documents were read in the first
place.

The tag now builds the two DOM trees itself with a DocumentBuilder from
Commons Secure XML and hands those to XMLUnit, so no external entity is
fetched on the comparison path either. The ignoreWhitespace attribute
still reaches the builder, as it did through XMLUnit's global setting.

A regression test compares a document whose DOCTYPE points to a DTD
that does not exist, with and without ignoreWhitespace, since the
latter routes the trees through XMLUnit's whitespace-stripping
transform.

Assisted-By: Claude Fable 5.1 <noreply@anthropic.com>
@garydgregory
garydgregory merged commit 6fa89a1 into apache:master Sep 17, 2026
9 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Thank you @ppkarwasz , merged 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants