[CALCITE-7601] Harden ST_GeomFromGML against external entity expansion - #5006
[CALCITE-7601] Harden ST_GeomFromGML against external entity expansion#5006alhudz wants to merge 5 commits into
Conversation
| factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); | ||
| factory.setFeature("http://xml.org/sax/features/external-general-entities", false); | ||
| factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); |
There was a problem hiding this comment.
Setting all three features is overkill, since disallow-doctype-decl will throw on a DOCTYPE declaration and will therefore not parse any external subset (non-validating/load-external-dtd) nor entities.
There was a problem hiding this comment.
Good catch, dropped both external-entity lines. disallow-doctype-decl throws on the DOCTYPE so nothing reaches the entity-resolution path anyway. Test still rejects the payload.
|
Thank you for your contribution @alhudz . Please refer to other PRs. We need Jira to illustrate the issue, and we strictly require that the submitted information be consistent with Jira's. |
|
Disclaimer: some shameless self-promotion 😉 Since changes like this one have been landing in many OSS projects lately, a month ago I wrote a small reusable library that hands you a hardened JAXP factory with a single method call: The library code itself wouldn't add much to a PR like this. What might be worth it is everything around the code: a continuously evolving test suite that runs against every JAXP implementation still in the wild, and the fact that a single dependency can act as a "scapegoat" for SAST tools and reviewers. Instead of every project re-deriving the full set of (often cargo-culted) properties and tripping XXE/SSRF warnings whenever one is missing, the hardening lives in one audited place. Note The library is incubating, with the hope of landing in either Apache Commons or Xerces. I haven't had definitive feedback from either project yet, so I'll keep maintaining it for the foreseeable future. |
|
I have created CALCITE-7601 to track this issue and have updated the PR information to reference the Jira so that the descriptions remain consistent. |
|
Pushed a fix for the |
|
Pushed a fix for the failing |
|
This is better, but the checker framework is still unhappy |
|
That was the null delegate passed to |
|
I am curious: where does CheckerFramework take the information those arguments should not be null? I don't see any annotations in |
|
Please be aware that there's been some discussion within Calcite PMC to decide whether or not we should accept this patch; and it seems that, for the moment, the PMC leans towards not accepting it (and consider that this falls under JTS responsibility). |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions. |
Jira Link
A Jira can be filed for this if preferred; raising the patch first since the change is small and self-contained.
Changes Proposed
Repro:SELECT ST_GeomFromGML(g)wheregis a GML string carrying a DOCTYPE with an external entity, e.g.<!DOCTYPE x [ <!ENTITY e SYSTEM "file:///etc/passwd"> ]>referenced from<gml:coordinates>&e;,0</gml:coordinates>.Expected:the entity is not resolved.Actual:fromGmlbuilds a JTSGMLReader, whose internalSAXParserFactoryleaves DOCTYPE and external general/parameter entities enabled, so the parser fetches the entity target and inlines it into the geometry. That is local file read / SSRF (XXE) from row data, since the GML argument crosses the trust boundary at theST_GeomFromGMLSQL function.Fix:parse with aSAXParserconfigured withdisallow-doctype-decland external entities off, feeding JTS's ownGMLHandler. Same hardening already used inXmlFunctionsandDiffRepository.Test:SpatialTypeUtilsTestgets a regression that points an external entity at a temp file holding a valid coordinate, so an unguarded parser would returnPOINT (7 8)while the guarded one rejects the document.