GHSA-jqh6-9574-5x22
MITM based Zip Slip in `ca.uhn.hapi.fhir:org.hl7.fhir.core`
Quick fix
GHSA-jqh6-9574-5x22 — ca.uhn.hapi.fhir:org.hl7.fhir.core: upgrade to the fixed version with the command below.
# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.coreDetails
### 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. - https://github.com/hapifhir/org.hl7.fhir.core/blob/f58b7acfb5e393cac52cc5bbb170bdb669c2880e/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java - https://github.com/hapifhir/org.hl7.fhir.core/blob/f58b7acfb5e393cac52cc5bbb170bdb669c2880e/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java
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
- https://snyk.io/research/zip-slip-vulnerability
Are you affected?
Enter the version of the package you're using.
Affected packages
0Fixed in: 5.6.92# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.core0Fixed in: 5.6.92# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.convertors0Fixed in: 5.6.92# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.r4b0Fixed in: 5.6.92# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.r50Fixed in: 5.6.92# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.utilities0Fixed in: 5.6.92# pom.xml: bump <version>5.6.92</version> for ca.uhn.hapi.fhir:org.hl7.fhir.validationReferences
- https://github.com/HL7/fhir-ig-publisher/security/advisories/GHSA-xr8x-pxm6-prjg[WEB]
- https://github.com/hapifhir/org.hl7.fhir.core/security/advisories/GHSA-jqh6-9574-5x22[WEB]
- https://nvd.nist.gov/vuln/detail/CVE-2023-24057[ADVISORY]
- https://github.com/hapifhir/org.hl7.fhir.core/commit/b50aec59124416b7315a49220cfc3999223414cc[WEB]
- https://github.com/hapifhir/org.hl7.fhir.core[PACKAGE]
Check it before you install it
One call answers whether to add this package: known advisories, CISA KEV, and whether the name is a hallucinated or freshly squatted one. No key needed to try it.
curl -s https://vdb.ai.kr/v1/ai/check-packages \
-H 'Content-Type: application/json' \
-d '{"packages":["pkg:maven/ca.uhn.hapi.fhir/org.hl7.fhir.core"]}'