COMMONSXML-6: XMLInputFactory: capability-driven hardening - #12
Merged
garydgregory merged 2 commits intoJul 5, 2026
Merged
Conversation
Replace the per-implementation class-name dispatch for StAX with a single capability-driven recipe, mirroring the DocumentBuilderFactory and SAXParserFactory rework. A new StaxHardener consolidates the JDK Zephyr and Woodstox recipes into one pass that probes which properties each factory accepts and adapts: - Limits are applied best-effort by Limits.tryApply(XMLInputFactory), which sets both the JDK URL limit properties and the Woodstox com.ctc.wstx.* properties; each implementation honours its own and rejects the other's. - The external DTD subset is skipped via Zephyr's ignore-external-dtd (best-effort) so a DOCTYPE-only document still parses without a fetch attempt. - External entities are denied through resolvers, leaving the standard SUPPORT_DTD / IS_SUPPORTING_EXTERNAL_ENTITIES defaults untouched. Woodstox exposes fine-grained hooks (dtdResolver, entityResolver, undeclaredEntityResolver), so when all three apply the factory is Woodstox; any factory that does not accept that trio (the JDK Zephyr, or an unrecognized implementation) instead gets a single deny-all XMLResolver via setXMLResolver. JaxpSetters gains trySetProperty(XMLInputFactory) and setOptionalProperty(XMLInputFactory). Limits.tryApply(XMLInputFactory) replaces applyToJdkStax and applyToWoodstox. WoodstoxProvider and StockJdkProvider.configure(XMLInputFactory) are removed; XmlFactories.newXMLInputFactory() routes through StaxHardener. The DTD_SUBSET_ONLY resolver moves to StaxHardener, and its SpotBugs known-null exclusion moves with it. An implementation is no longer rejected for being unrecognized: it is hardened best-effort, with the deny-all XMLResolver as the fallback. The throw-on-external -entity behaviour of both bundled parsers is preserved, so the StAX attack tests are unchanged. Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
The Jira ticket is COMMONSXML-6 |
Member
|
Hi @ppkarwasz |
Member
Author
|
I resolved the conflicts in both this and #13. I will also submit one last PR of this series that refactors
|
Member
|
Merged, thank you @ppkarwasz 🚀 |
Member
|
@ppkarwasz |
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.
Applies the COMMONSXML-1 capability-driven approach to the StAX path, replacing the per-implementation class-name dispatch for
XMLInputFactorywith a singleStaxHardener.ACCESS_EXTERNAL_*, soStaxHardener.hardenconsolidates the JDK Zephyr and Woodstox recipes into one pass: apply limits and Zephyrignore-external-dtdbest-effort, try the Woodstox resolver trio, and fall back to a single deny-allXMLResolverwhen that trio is not accepted.SUPPORT_DTD/IS_SUPPORTING_EXTERNAL_ENTITIESdefaults untouched, so both bundled parsers keep their original throw-on-external-entity behavior.Limits.tryApply(XMLInputFactory)replacesapplyToJdkStax/applyToWoodstox;JaxpSettersgainstrySetProperty(XMLInputFactory)andsetOptionalProperty(XMLInputFactory).WoodstoxProviderandStockJdkProvider.configure(XMLInputFactory)are removed;XmlFactories.newXMLInputFactory()routes throughStaxHardener. TheDTD_SUBSET_ONLYresolver and its SpotBugs known-null exclusion move with it.Behaviour: an unrecognized StAX implementation is now hardened best-effort (deny-all
XMLResolver) instead of being rejected; on such an implementation that fallback also denies the external subset, so a DOCTYPE-only document may fail (fail-closed). The StAX attack tests are unchanged.mvn verifygreen across the stock JDK (Zephyr) and Woodstox profiles.