Skip to content

Use PipeParser for inbound HL7 to remove XML/XXE attack surface (2.7.x backport of #6223)#6321

Open
dkayiwa wants to merge 1 commit into
openmrs:2.7.xfrom
dkayiwa:security/hl7-xxe-parser-2.7.x
Open

Use PipeParser for inbound HL7 to remove XML/XXE attack surface (2.7.x backport of #6223)#6321
dkayiwa wants to merge 1 commit into
openmrs:2.7.xfrom
dkayiwa:security/hl7-xxe-parser-2.7.x

Conversation

@dkayiwa

@dkayiwa dkayiwa commented Jul 15, 2026

Copy link
Copy Markdown
Member

Backport of #6223 to the 2.7.x maintenance line.

The hL7Parser bean on 2.7.x is a HAPI GenericParser, which routes XML-encoded payloads to HAPI's XML parser. On hapi-base 2.1 that parser builds an LSParser with no XXE hardening, so an XML message with a DOCTYPE/external entity yields XXE (local file reads, SSRF, entity-expansion DoS). Inbound HL7 parsing runs before the authorization check, so the surface is reachable without authentication.

master removed this in #6223; 2.7.x/2.8.x/2.9.x still ship the GenericParser bean.

Switches the bean to PipeParser (ER7 only), which rejects XML outright before any XML processing; widens HL7ServiceImpl.parser to the Parser supertype so the XML setter injection still resolves; adds a regression test.

Addresses GHSA-27xq-2wmf-6hpg and GHSA-2h4h-2mf9-836w on 2.7.x.

Backport of openmrs#6223 to 2.7.x.

The hL7Parser bean was a HAPI GenericParser, which auto-detects message
encoding and routes XML-encoded payloads to HAPI's XML parser. On
hapi-base 2.1 that parser builds an unhardened LSParser (no
disallow-doctype-decl, external general/parameter entities enabled),
exposing XML external entity (XXE) processing: external file reads, SSRF
and entity-expansion DoS. Inbound HL7 parsing runs before authorization,
so the surface is reachable pre-auth.

OpenMRS only ever produces and consumes pipe-delimited (ER7) HL7v2, so the
XML branch is unused. Switch the bean to PipeParser, which rejects XML
payloads outright with an unsupported-encoding error. The HL7ServiceImpl
parser field and setter are widened to the common Parser supertype so the
existing XML setter injection still resolves. Adds a regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

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.

2 participants