← Back to Pull requests

Prevent XXE in the HL7 v2.x strict parser #408

Closed
unknown closed this pull request without merging on Sep 24, 2026 20:40 UTC
View on GitHub
unknown unknown commented on Aug 10, 2026 19:31 UTC
Author

Summary

The HL7 v2.x strict parser hands XML-encoded inbound messages to the bundled HAPI 2.3, whose XMLUtils.parse resolves 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 reject DOCTYPE declarations, matching the disallow-doctype-decl hardening already used on the sibling fromXML path (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 the fromXML side.) 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

  • Confirmed the vulnerability at the bytecode level. Disassembled hapi-base-2.3.jar: XMLUtils sets no doctype or external-entity restrictions.

  • Confirmed the fix is comprehensive at a single chokepoint. parseStringIntoDocument is the only caller of XMLUtils.parse across all HAPI parser classes, and both of OIE's parser instances (serialization + deserialization) are the overridden CustomDefaultXMLParser — it is the only HAPI XML parser instantiated in the server/donkey tree.

  • Live MLLP before/after (the authoritative proof). Imported the xxe-poc channel (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 toXML path and assert the parse is rejected with a DOCTYPE-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 testToXmlStrictValidatingKeepsCdataContent and by smoke case 111-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 upgrade — the hapi-structures 2.3 → 2.6.0 bump is tracked by Renovate in the Dependency Dashboard (#386); the vendored hapi-base jar needs replacing alongside it. This override should stay even after the upgrade: HAPI's 2.4+ fix leaves disallow-doctype-decl=false (permits a DOCTYPE, only disables entity resolution), so this refusal is the stronger posture.

  • Optional surface reduction — an "Allow XML" data type toggle to let a strict HL7 channel refuse XML input entirely (mgaffigan's #406) is a separate enhancement, not a security control, and is deliberately out of scope here.

  • A distinct XXE in the generic XML data type's batch adaptor (XMLBatchAdaptor parses inbound content with an unhardened XPathFactory) 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.

    Diff: 527 lines (+395 / -132) across 6 files Reviewer: gibson9583 Review duration: 64869m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.9% · Safe to merge
    18.9%