Skip to content

add opt-in to disable external DTD access in JAXPValidator - #331

Merged
bodewig merged 1 commit into
xmlunit:mainfrom
jmestwa-coder:jaxp-validator-external-dtd
Jun 20, 2026
Merged

add opt-in to disable external DTD access in JAXPValidator#331
bodewig merged 1 commit into
xmlunit:mainfrom
jmestwa-coder:jaxp-validator-external-dtd

Conversation

@jmestwa-coder

@jmestwa-coder jmestwa-coder commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

By default JAXPValidator leaves external DTD access enabled, matching the conscious decision documented in the 2.6.0 release notes. This keeps that default unchanged and adds an opt-in for callers who validate untrusted input.

  • new setDisableExternalDtdAccess(boolean) on JAXPValidator, default false so existing behavior is unchanged
  • when enabled, sets accessExternalDTD to the empty string on the SchemaFactory and the Validator
  • accessExternalSchema is left untouched so xs:import and xsi:schemaLocation keep working
  • added a stronger note to the class javadoc about the default
  • test covers the opt-in path

@bodewig

bodewig commented Jun 20, 2026

Copy link
Copy Markdown
Member

this has been a conscious decision and even been documented as such, see the {release notes of 2.6.](https://github.com/xmlunit/xmlunit/blob/main/RELEASE_NOTES.md#xmlunit-for-java-260---released-2018-04-22)

I wouldn't be opposed to added a stronger warning to the class' javadocs - nor to adding SchemaFactorConfigurer and ValidatorConfigurer classes similar to org.xmlunit.util.DocumentBuilderFactoryConfigurer so disabling acces would be easier for people who want to disable it. We may as well do so with a new setting on JAXPValidator, but I really do not want to change the default here.

The context of the validation package is one where I strongly believe people will only use it on trusted inputs. And if they don't there are warnings already in place.

@jmestwa-coder
jmestwa-coder force-pushed the jaxp-validator-external-dtd branch from 3ef3e81 to 2049841 Compare June 20, 2026 13:46
@jmestwa-coder jmestwa-coder changed the title disable external DTD access in JAXPValidator add opt-in to disable external DTD access in JAXPValidator Jun 20, 2026
@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

makes sense, the 2.6.0 note is clear and I don't want to change that default either. I've reworked this to leave the default alone and added an opt-in setDisableExternalDtdAccess(boolean) instead, plus a stronger warning in the class javadoc. The test now flips the flag on.

If you'd rather have reusable SchemaFactoryConfigurer/ValidatorConfigurer classes than a one-off setter, I'm happy to go that route instead, just say the word.

@jmestwa-coder
jmestwa-coder force-pushed the jaxp-validator-external-dtd branch from 2049841 to 1b209eb Compare June 20, 2026 13:48
@bodewig

bodewig commented Jun 20, 2026

Copy link
Copy Markdown
Member

I'm fine with the one-off setter unless you believe there are other places in XMLUnit that would benefit from the configurer. I don't believe SchemaFactory or Validator are used anywhere else (outside of the legacy project), though.

@bodewig
bodewig merged commit 0a1885b into xmlunit:main Jun 20, 2026
bodewig added a commit that referenced this pull request Jun 20, 2026
@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

agreed, the setter's the right scope here. JAXPValidator is the only spot outside the legacy project that touches SchemaFactory/Validator, so a shared configurer wouldn't really buy anything. thanks for merging.

pull Bot pushed a commit to boost-mw-poc/xmlunit_xmlunit that referenced this pull request Jun 20, 2026
@bodewig bodewig added this to the 2.13.0 milestone Jul 31, 2026
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