Skip to content

MITM based Zip Slip in `ca.uhn.hapi.fhir:org.hl7.fhir.core`

Critical severity GitHub Reviewed Published Jan 23, 2023 in hapifhir/org.hl7.fhir.core • Updated Feb 28, 2023

Package

maven ca.uhn.hapi.fhir:org.hl7.fhir.convertors (Maven)

Affected versions

< 5.6.92

Patched versions

5.6.92
maven ca.uhn.hapi.fhir:org.hl7.fhir.core (Maven)
< 5.6.92
5.6.92
maven ca.uhn.hapi.fhir:org.hl7.fhir.r4b (Maven)
< 5.6.92
5.6.92
maven ca.uhn.hapi.fhir:org.hl7.fhir.r5 (Maven)
< 5.6.92
5.6.92
maven ca.uhn.hapi.fhir:org.hl7.fhir.utilities (Maven)
< 5.6.92
5.6.92
maven ca.uhn.hapi.fhir:org.hl7.fhir.validation (Maven)
< 5.6.92
5.6.92

Description

Impact

MITM can enable Zip-Slip.

Vulnerability

Vulnerability 1: Scanner.java

There is no validation that the zip file being unpacked has entries that are not maliciously writing outside of the intended destination directory.
https://github.com/hapifhir/org.hl7.fhir.core/blob/8c43e21094af971303131efd081503e5a112db4b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Scanner.java#L335-L357

This zip archive is downloaded over HTTP instead of HTTPS, leaving it vulnerable to compromise in-flight.
https://github.com/hapifhir/org.hl7.fhir.core/blob/8c43e21094af971303131efd081503e5a112db4b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Scanner.java#L136

Vulnerability 2: TerminologyCacheManager.java

Note: While these links point to only one implementation, both implementations of TerminologyCacheManager.java are vulnerable to this as their code seems to be duplicated.

While there is validation in this bit of logic that attempts to validate that the zip file doesn't contain malicious entries that escape the destination directory, the guard is insufficient.

https://github.com/hapifhir/org.hl7.fhir.core/blob/f58b7acfb5e393cac52cc5bbb170bdb669c2880e/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java#L97-L113

This is because the Utilities.path(String... path) method does not normalize the path, although it seems to be attempting to do so.
https://github.com/hapifhir/org.hl7.fhir.core/blob/f58b7acfb5e393cac52cc5bbb170bdb669c2880e/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java#L617-L675

The normalization only occurs if the path element starts with a path traversal payload. As an example, calling Utilities.path("/base", "/child/../test") will return the string "/base/child/../test".

This guard logic can, thus, be easily bypassed:
https://github.com/hapifhir/org.hl7.fhir.core/blob/f58b7acfb5e393cac52cc5bbb170bdb669c2880e/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java#L100-L104

Assuming an attacker can control the return value of ze.getName(), they can supply a value like /anything/../../../../zipsip-protection-bypass.txt.

Similarly, an attacker can control the contents of the Zip file via a MITM attack as this logic is used with resources not downloaded over HTTPS.

https://github.com/hapifhir/org.hl7.fhir.core/blob/f58b7acfb5e393cac52cc5bbb170bdb669c2880e/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java#L66-L73

Patches

Unknown

Workarounds

Unknown

References

References

@dotasek dotasek published to hapifhir/org.hl7.fhir.core Jan 23, 2023
Published to the GitHub Advisory Database Jan 23, 2023
Reviewed Jan 23, 2023
Published by the National Vulnerability Database Jan 26, 2023
Last updated Feb 28, 2023

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
High
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H

EPSS score

0.229%
(62nd percentile)

Weaknesses

CVE ID

CVE-2023-24057

GHSA ID

GHSA-jqh6-9574-5x22

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.