Skip to content

[CALCITE-7601] Harden ST_GeomFromGML against external entity expansion - #5302

Draft
ppkarwasz wants to merge 2 commits into
apache:mainfrom
ppkarwasz:feat/gml-commons-secure-xml
Draft

ppkarwasz wants to merge 2 commits into
apache:mainfrom
ppkarwasz:feat/gml-commons-secure-xml

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

Jira Link

CALCITE-7601

Changes Proposed

Note

This is a fallback PR. The preferred fix is upstream in JTS, where GMLReader would create its parser through Apache Commons Secure XML: locationtech/jts#1230. This PR is only needed if JTS does not adopt that change, or if Calcite cannot wait for a JTS release that includes it.

ST_GeomFromGML no longer uses JTS's GMLReader, whose SAX parser resolves external entities. It parses the GML with a SAX parser from Apache Commons Secure XML 1.0.0, which does not fetch external DTDs or entities, and passes the events to JTS's own GMLHandler.

  • The parser is not namespace-aware, like GMLReader, so GML fragments with an undeclared gml: prefix, such as the output of ST_AsGML, are still accepted.
  • A forbidden-apis rule rejects GMLReader and the plain JAXP SAX factory methods, so the unsecured path cannot come back.
  • There are no new XXE tests: the guarantees belong to Commons Secure XML and are tested there.

🤖 Generated with Claude Code

ST_GeomFromGML used JTS's GMLReader, which creates a plain SAX parser
with external entity resolution enabled. It now parses the GML with a
SAX parser from Apache Commons Secure XML, which does not fetch external
DTDs or entities, and passes the events to JTS's GMLHandler.

The parser is not namespace-aware, like GMLReader, so GML fragments
with an undeclared "gml:" prefix, such as the output of ST_AsGML, are
still accepted.

A forbidden-apis rule rejects GMLReader and the plain JAXP SAX factory
methods.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@ppkarwasz

Copy link
Copy Markdown
Member Author

commons-secure-xml will be a dependency of commons-text, commons-configuration2 and commons-digester in the next iteration of releases, therefore it will become a transitive dependency of Calcite anyway.

Gradle may run on Java 8 or 11, where signatures of the Java 9 and 13
SAXParserFactory methods fail to parse. Code compiled for Java 8 cannot
call those methods anyway.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

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