Harden XML parsing via commons-secure-xml - #766
Draft
ppkarwasz wants to merge 4 commits into
Draft
Conversation
Create XmlStringLookup's document builder and XPath factories through org.apache.commons:commons-secure-xml. The secure factories enable FEATURE_SECURE_PROCESSING and install a non-removable entity-resolver floor on every parser they produce: external DTD and entity lookups are resolved to empty content instead of being fetched, and internal entity expansion is bounded, regardless of the JAXP implementation on the classpath. Changes: - Add the commons-secure-xml dependency (1.0.0-SNAPSHOT until its first release). - Route factory creation through SecureDocumentBuilderFactory and SecureXPathFactory in XmlStringLookup when the instance's feature map enables secure processing. The documented opt-outs keep their meaning: feature maps without secure processing, and the standard javax.xml.accessExternalDTD system property (which the secure factory's resolver floor would otherwise ignore), keep using the plain JAXP factories, so external entity resolution can be restored where it is wanted. - Adapt the secure-path tests to the secure contract: a parser may either reject a document with an external reference or parse it with the reference resolved to empty content; the tests now assert that the external content does not leak into the result instead of expecting one fixed failure mode. - Run the CI and CodeQL builds with -Puse-apache-snapshots (inherited from the org.apache:apache parent POM) so the commons-secure-xml SNAPSHOT resolves; CodeQL's autobuild receives the profile through MAVEN_ARGS. Assisted-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHgnMnGWHQoH2zD2jFdoMT
ppkarwasz
force-pushed
the
feat/use-commons-xml
branch
from
August 31, 2026 15:16
68e8cc3 to
f758b18
Compare
Bump org.apache.commons:commons-secure-xml from 1.0.0-SNAPSHOT to 1.0.0 and add the temporary staging repository https://repository.apache.org/content/repositories/orgapachecommons-1962/ after Central, so the vote gets downstream CI results. Drop the -Puse-apache-snapshots profile from the CI workflows, which the release version no longer needs. Remove the staging repository once 1.0.0 is released. Assisted-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0167e29ScPEdfzJnEFm95imK
garydgregory
reviewed
Sep 6, 2026
garydgregory
reviewed
Sep 6, 2026
garydgregory
reviewed
Sep 6, 2026
Commons Secure XML blocks external resource fetching with an entity resolver rather than with parser features, so the opt-outs the previous commit documented never worked: neither a feature map without secure processing nor the javax.xml.accessExternalDTD system property reaches the resolver floor. Always create the factories through SecureDocumentBuilderFactory and SecureXPathFactory instead. Changes: - Remove the plain-JAXP fallback from XmlStringLookup.lookup(String), along with the DEFAULT_XML_FEATURES and DEFAULT_XPATH_FEATURES maps that only existed to select it. - Document the two aspects Commons Secure XML secures separately: FEATURE_SECURE_PROCESSING governs processing limits and remains settable, while external DTD subsets and entities are blocked outright and cannot be re-enabled. - Remove the references to the "XmlStringLookup.secure" system property, which was never introduced. - Disable the tests that expect an external entity to resolve, and tighten the leak assertion now that the parser no longer rejects such documents. - Shorten the changelog entry and state the behavior change. Assisted-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y7VfssZLkK11bBY2kVyyY4
ppkarwasz
marked this pull request as ready for review
September 8, 2026 07:50
garydgregory
requested changes
Sep 8, 2026
|
|
||
| @Test | ||
| @SetSystemProperty(key = "XmlStringLookup.secure", value = "false") | ||
| @Disabled("External entities are blocked by Commons Secure XML through an entity resolver and can no longer be re-enabled.") |
Member
There was a problem hiding this comment.
That's not right. There should be 2 tests instead of disabling this one. 1) this test is enabled and asserts the new default behavior. 2) shows how to override the behavior to get the old one back.
garydgregory
reviewed
Sep 8, 2026
|
|
||
| @Test | ||
| @SetSystemProperty(key = "javax.xml.accessExternalDTD", value = "file") | ||
| @Disabled("External entities are blocked by Commons Secure XML through an entity resolver and can no longer be re-enabled.") |
garydgregory
reviewed
Sep 8, 2026
|
|
||
| @Test | ||
| @SetSystemProperty(key = "javax.xml.accessExternalDTD", value = "file") | ||
| @Disabled("External entities are blocked by Commons Secure XML through an entity resolver and can no longer be re-enabled.") |
garydgregory
marked this pull request as draft
September 8, 2026 11:28
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.
Creates
XmlStringLookup's document builder and XPath factories throughorg.apache.commons:commons-secure-xml(1.0.0-SNAPSHOT until its first release) on the default path. The secure factories enable XML secure processing and install a non-removable entity-resolver floor: external DTD and entity lookups are resolved to empty content instead of being fetched, and internal entity expansion is bounded. The documentedXmlStringLookup.secure=falsesystem property keeps its meaning: that path still uses the plain JAXP factories, so external entity resolution can be restored where it is wanted.The secure-path tests are adapted to the secure contract: a parser may either reject a document with an external reference or parse it with the reference resolved to empty content, so they now assert that the external content does not leak into the result instead of expecting one fixed failure mode. CI and CodeQL run with
-Puse-apache-snapshotsso the SNAPSHOT dependency resolves.🤖 Generated with Claude Code