Skip to content

Harden XML parsing via commons-secure-xml - #108

Draft
ppkarwasz wants to merge 2 commits into
masterfrom
feat/use-commons-xml
Draft

Harden XML parsing via commons-secure-xml#108
ppkarwasz wants to merge 2 commits into
masterfrom
feat/use-commons-xml

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

Warning

This PR was submitted automatically to smoke-test
Apache Commons Secure XML
and has not yet been verified by a human.
It will stay a draft until a committer reviews it and marks it ready.

Creates SAX parsers and readers through org.apache.commons:commons-secure-xml (1.0.0-SNAPSHOT until its first release) in core, jelly-tags/xml and jelly-tags/xmlunit. The secure factory enables XML secure processing and installs 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.

  • core XMLParser keeps the documented JellyContext.setAllowDtdToCallExternalEntities(true) opt-in working by using a plain factory on that path; the default path uses the secure factory, and a factory assigned to the protected static field still wins.
  • core ParseTag, which had no hardening at all, now creates its reader through the secure factory.
  • jelly-tags/xml: TransformTag's readers and ParseTag's dom4j SAXReader are built from the secure factory (the deprecated org.xml.sax.driver system property no longer selects the reader class). The TransformerFactory itself stays unsecured for now: Xalan, which this module puts on the class path, drops the attributes of xsl:namespace-alias literal result elements under secure processing (XSLTElementProcessor rejects "foreign" attributes as non-fatal errors), silently breaking stylesheets such as the Schematron skeleton.
  • jelly-tags/xmlunit: the assertion tags' dom4j SAXReaders are built from the secure factory. jelly-tags/html is unchanged (NekoHTML is an HTML scanner, not an XML parser).
  • CI and CodeQL run with -Puse-apache-snapshots so the SNAPSHOT dependency resolves.

🤖 Generated with Claude Code

Create SAX parsers and readers through
org.apache.commons:commons-secure-xml. The secure factory enables
FEATURE_SECURE_PROCESSING and installs a non-removable entity-resolver
floor on every parser it produces: external DTD and entity lookups that
a caller-set resolver does not resolve 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) to core, jelly-tags/xml and jelly-tags/xmlunit.
- core XMLParser keeps the documented
  JellyContext.setAllowDtdToCallExternalEntities(true) opt-in working by
  using a plain factory on that path; the default path uses the secure
  factory, and a factory assigned to the protected static field still
  wins. The flag-dependent choice is no longer cached in that field.
- core ParseTag (which had no hardening at all) now creates its reader
  through the secure factory.
- jelly-tags/xml: TransformTag's readers and ParseTag's dom4j SAXReader
  are built from the secure factory; dom4j and XMLReaderFactory
  otherwise provision readers through JAXP at their own defaults, and
  the deprecated org.xml.sax.driver system property no longer selects
  the reader class. The TransformerFactory itself stays unsecured for
  now: Xalan, which this module puts on the class path, drops the
  attributes of xsl:namespace-alias literal result elements under
  secure processing (XSLTElementProcessor rejects "foreign" attributes
  as non-fatal errors), silently breaking stylesheets such as the
  Schematron skeleton.
- jelly-tags/xmlunit: the assertion tags' dom4j SAXReaders are built
  from the secure factory.
- jelly-tags/html is unchanged: NekoHTML is an HTML scanner, not an XML
  parser.
- 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
ppkarwasz force-pushed the feat/use-commons-xml branch from 7278e24 to 55c5bad Compare August 31, 2026 15:10
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
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.

1 participant