Skip to content

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

Merged
garydgregory merged 3 commits into
masterfrom
feat/use-commons-xml
Sep 6, 2026
Merged

Harden XML parsing via commons-secure-xml#288
garydgregory merged 3 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 XML parsers and transformers through org.apache.commons:commons-secure-xml (1.0.0-SNAPSHOT until its first release). The secure factories enable XML secure processing and install a non-removable entity-resolver floor: external DTD, entity, schema and XInclude lookups that a caller-set resolver does not resolve are resolved to empty content instead of being fetched, and internal entity expansion is bounded.

  • DOMParser goes through SecureDocumentBuilderFactory and XMLDocumentContainer through SecureTransformerFactory; the caller-configurable settings (validation, namespace awareness, entity expansion, whitespace, comments, coalescing) keep working.
  • JDOMParser builds its SAX reader through the secure factory as well, by overriding SAXBuilder.createParser(); documents with internal DTD subsets parse as before.
  • Parsers registered through DocumentContainer.registerXMLParser remain under the control of their authors.
  • CI and CodeQL run with -Puse-apache-snapshots so the SNAPSHOT dependency resolves.

🤖 Generated with Claude Code

Create XML parsers and transformers through
org.apache.commons:commons-secure-xml. The secure factories enable
FEATURE_SECURE_PROCESSING and install a non-removable entity-resolver
floor on every parser they produce: external DTD, entity, schema and
XInclude 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).
- Route factory creation through SecureDocumentBuilderFactory in
  DOMParser and SecureTransformerFactory in XMLDocumentContainer; the
  caller-configurable factory settings (validation, namespace awareness,
  entity expansion, whitespace, comments, coalescing) keep working.
- JDOMParser builds its SAX reader through the secure factory as well,
  by overriding SAXBuilder.createParser(); documents with internal DTD
  subsets parse as before.
- Parsers registered through DocumentContainer.registerXMLParser remain
  under the control of their authors.
- 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 f9af9ef to 915bc09 Compare August 31, 2026 15:06
ppkarwasz and others added 2 commits September 3, 2026 07:04
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
throw new JDOMException("Unable to create a new XML reader", ex);
}
}
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppkarwasz Why aren't the other builder setters in the try block?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

This value is set on the factory, the others on the builder.

BTW: we are still using JDOM 1, which was released 14 years ago, instead of JDOM 2, which is more recent although mostly dormant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be a good update! I'm not sure if JDOM 1 objects have leaked into public or protected API signatures though... that would be a non-starter with a major release line. Let's if I resolved the conflicts correctly in the GH web UI: #87

@garydgregory
garydgregory marked this pull request as ready for review September 6, 2026 12:54
@garydgregory
garydgregory merged commit 9024498 into master Sep 6, 2026
19 checks passed
@garydgregory
garydgregory deleted the feat/use-commons-xml branch September 6, 2026 13:22
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