Prevent XXE in the HL7 v2.x strict parser #408
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 527 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.375
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #408"
general
weight: 0.35
gibson9583
Summary
The HL7 v2.x strict parser hands XML-encoded inbound messages to the bundled HAPI 2.3, whose
XMLUtils.parseresolves external XML entities with no hardening. On a channel with Use Strict Parser + Validate in Strict Parser, an unauthenticated message to the MLLP/TCP listener could trigger SSRF (internal services, cloud metadata) and local file disclosure. Reported as oie-1; also independently reported by Samuel Paschuan.Fix
ER7Serializer.CustomDefaultXMLParser.parseStringIntoDocument— the sole path from OIE to the vulnerable parser — is overridden to rejectDOCTYPEdeclarations, matching thedisallow-doctype-declhardening already used on the siblingfromXMLpath (and ~20 other XML parse sites in the tree).This is a minimal, non-breaking change. The format the strict parser handles — the official HL7 v2.xml encoding (
urn:hl7-org:v2xml) — is defined by XML Schema, not DTDs, so a standards-conformant message does not use a DOCTYPE and is unaffected. (This is distinct from Mirth's own non-strict<HL7Message>format, which is a separate code path the override does not touch, and which is already DOCTYPE-hardened on thefromXMLside.) Any inbound message that does carry a DOCTYPE is now rejected rather than parsed — that is the intended hardening, since at the parser level a DOCTYPE-bearing message is indistinguishable from the attack. Existing channels need no changes: no new options, no migration, no configuration.How this was verified
hapi-base-2.3.jar:XMLUtilssets no doctype or external-entity restrictions.parseStringIntoDocumentis the only caller ofXMLUtils.parseacross all HAPI parser classes, and both of OIE's parser instances (serialization + deserialization) are the overriddenCustomDefaultXMLParser— it is the only HAPI XML parser instantiated in the server/donkey tree.xxe-pocchannel (MLLP :6661, strict + strict validation), sent the report's payload against an out-of-band HTTP catcher:- Unpatched build: the catcher logged the callback — SSRF fired, unauthenticated.
- Patched build:
DOCTYPE is disallowed— the message is rejected and the server never calls out.Tests
Unit tests fire the report's payload on the strict
toXMLpath and assert the parse is rejected with aDOCTYPE-disallowed root cause, alongside a benign v2.xml message that still round-trips (the hardening does not break valid XML).A CDATA field in a strict-parsed v2.xml message keeps its value. This is covered by
testToXmlStrictValidatingKeepsCdataContentand by smoke case111-hl7-strict-xml-cdata, which checks the stored transformed message on a running engine.Honest caveat: the DOCTYPE-rejection unit test asserts the intended behavior but does not by itself discriminate patched from unpatched, because the test-JVM's default XML parser rejects a DOCTYPE regardless — the engine runtime is where HAPI resolves a different, vulnerable parser. The discriminating before/after evidence is the live MLLP reproduction above.
Follow-ups (separate)
hapi-structures2.3 → 2.6.0 bump is tracked by Renovate in the Dependency Dashboard (#386); the vendoredhapi-basejar needs replacing alongside it. This override should stay even after the upgrade: HAPI's 2.4+ fix leavesdisallow-doctype-decl=false(permits a DOCTYPE, only disables entity resolution), so this refusal is the stronger posture.XMLBatchAdaptorparses inbound content with an unhardenedXPathFactory) was found during this work and will be filed and fixed separately.Credits
Thanks to Samuel Paschuan for reporting the issue, and to Michael Gaffigan (@mgaffigan) and Tony Germano for the design discussion.