Skip to content

disable external entities in ParsingValidator instance parsing - #332

Merged
bodewig merged 2 commits into
xmlunit:mainfrom
jmestwa-coder:parsing-validator-external-entities
Jun 20, 2026
Merged

disable external entities in ParsingValidator instance parsing#332
bodewig merged 2 commits into
xmlunit:mainfrom
jmestwa-coder:parsing-validator-external-entities

Conversation

@jmestwa-coder

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

Copy link
Copy Markdown
Contributor

ParsingValidator.validateInstance parses the instance document with a validating SAX parser that resolves external entities, so a DOCTYPE in the instance can read local files or hit URLs through SYSTEM entities. The schema/DTD to validate against is resolved separately via the Handler, the instance never needs its own external entities.

Per the discussion this keeps the 2.6.0 default unchanged and adds an opt-in instead of changing behavior for everyone:

  • new setDisableExternalEntities(boolean) on ParsingValidator, default false so existing behavior is unchanged
  • when enabled, turns off external-general-entities and external-parameter-entities on the factory before the parser is created; DTD and schema validation are unaffected
  • stronger security note in the class javadoc plus a package-level warning in package-info.java covering both validators
  • test flips the flag on

@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

any update?

@bodewig

bodewig commented Jun 20, 2026

Copy link
Copy Markdown
Member

see the comments in #331 - this is the same case in that I explicitly decided to leave the defaults insecure back then.

@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

makes sense, I hadn't clocked that this was a documented decision back in 2.6, so I won't push to change the default. happy to close this one, or rework it into an opt-in setting / configurer like you described on #331 if that's useful. whichever you prefer.

@bodewig

bodewig commented Jun 20, 2026

Copy link
Copy Markdown
Member

I hadn't clocked that this was a documented decision back in 2.6,

Don't worry, it has been hidden well enough.

I believe an opt-in and a more explicit warning in the javadocs may be fine. Together with #331 maybe the warnung should be at the package level.

keep the 2.6.0 default of resolving external entities, add an opt-in
setter and document the XXE risk at the package and class level
@jmestwa-coder

Copy link
Copy Markdown
Contributor Author

reworked this the same way as #331: default stays as-is, added an opt-in setDisableExternalEntities(boolean) that only flips off the external-general/parameter-entity features when set. put the security warning at the package level in package-info.java so it covers both validators, with a short pointer on each class. test flips the flag on now.

@bodewig

bodewig commented Jun 20, 2026

Copy link
Copy Markdown
Member

many thanks

@bodewig
bodewig merged commit 9e4f6cd into xmlunit:main Jun 20, 2026
bodewig added a commit that referenced this pull request Jun 20, 2026
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