ST_GeomFromGML should not resolve external XML entities#5100
Open
Samin061 wants to merge 2 commits into
Open
Conversation
Member
|
Is there a corresponding Jira ticket for this? Also, please address the CI issues. |
Signed-off-by: bibi samina <sam@bugqore.com>
Contributor
Author
|
No Jira ticket yet. Happy to open a CALCITE issue if you'd like one for tracking. The failing check was CheckerFramework: it flagged the null delegate I passed to |
Contributor
|
Looks like a duplicate of #5006 ? |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Jira Link
Not filed yet; glad to open a CALCITE issue for tracking if you prefer one.
Changes Proposed
ST_GeomFromGMLhands the GML text straight toSpatialTypeUtils.fromGml, which parses it with JTSGMLReader. That reader builds a SAX parser from the JAXP defaults, so DOCTYPE declarations and external entities are resolved. The GML argument is ordinary untrusted data (a literal, parameter, or row value), so a document like<!DOCTYPE p [ <!ENTITY x SYSTEM "file:///etc/passwd"> ]>referenced from<gml:coordinates>reads a local file, and an external-DTD reference makes the parser open an outbound connection, giving both file disclosure and SSRF (XXE). The XML functions inXmlFunctionswere already hardened against this, but the spatial path slipped through because JTS constructs its own parser instead of reusing that configuration. I noticed it while checking which readers underruntimetouch untrusted XML. The fix builds the SAX parser insidefromGmlwithFEATURE_SECURE_PROCESSINGanddisallow-doctype-decland drives JTSGMLHandlerdirectly, matching the existing hardening; valid GML parses exactly as before, and the added test confirms a document carrying a DOCTYPE is rejected.Repro (with
fun=spatial):./gradlew :core:test(SpatialTypeUtilsTest, CoreQuidemTest), checkstyle, autostyle and forbiddenApis pass locally.