[2.x] OPENNLP-1835: Tolerate unsupported XML parser security options#1066
Merged
mawiesne merged 1 commit intoJun 5, 2026
Merged
Conversation
This was referenced Jun 2, 2026
rzo1
reviewed
Jun 3, 2026
rzo1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR. In general, it looks good to me. Left some comments.
We will need to port this to the 3.x line as well.
99571fe to
43ffe08
Compare
43ffe08 to
1fff0ab
Compare
2 tasks
Contributor
|
@RankoR Thanks for the PR! |
Contributor
Author
|
@mawiesne no problem! Do you have any estimates on the release date of this fix? |
Contributor
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.
There's no existing ticket for this issue.
For code changes:
What changed
OpenNLP 2.5.9 added stricter XML parser hardening in
XmlUtil, including JAXP external-access properties, implementation-specific parser features, and XInclude configuration.Some XML parser providers, including Android's, reject these optional settings even though they can still create a usable secure parser. This caused
XmlUtil.createDocumentBuilder()to fail during OpenNLP model initialization on Android.We faced this issue in SpeechServices in GrapheneOS: GrapheneOS/SpeechServices#18.
This PR keeps the hardening behavior where supported, but applies provider-specific XML security options defensively:
DocumentBuilderFactoryattributes are logged and ignoredA focused regression test was added using a custom
DocumentBuilderFactorythat rejects these optional settings.Verification
./mvnw -pl opennlp-tools -Dtest=XmlUtilTest test./mvnw -pl opennlp-tools testAlso manually verified with an SpeechServices app on a Pixel device.