Skip to content

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

Merged
dkayiwa merged 1 commit into
openmrs:2.9.xfrom
dkayiwa:security/hl7-xxe-parser-2.9.x
Jul 20, 2026
Merged

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

Conversation

@dkayiwa

@dkayiwa dkayiwa commented Jul 15, 2026

Copy link
Copy Markdown
Member

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

Why

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

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

Change

Switch the bean to PipeParser (ER7 only), which rejects XML outright with an unsupported-encoding error before any XML processing. HL7ServiceImpl's parser field and setter are widened to the common Parser supertype so the XML setter injection still resolves. Adds a regression test asserting an XML/DOCTYPE/external-entity payload is refused.

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

Backport of openmrs#6223 to 2.9.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

@dkayiwa
dkayiwa merged commit 4bbd072 into openmrs:2.9.x Jul 20, 2026
3 of 13 checks passed
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.

1 participant