GitHub Security Advisory: GHSA-hcm4-6hpj-vghm
Package: github.com/zarf-dev/zarf/src/pkg/archive (GO)
Severity: HIGH (CVSS 8.2)
CWE: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Vulnerable versions: >= 0.54.0, < 0.73.1
Patched in: 0.73.1

Summary: Zarf's symlink targets in archives are not validated against destination directory

Details:
### Summary

A path traversal vulnerability in archive extraction allows a specifically crafted Zarf package to create symlinks pointing outside the destination directory, enabling arbitrary file read or write on the system processing the package.

### What users should do
Upgrade immediately to version v0.73.1

If developers cannot upgrade immediately, only process Zarf packages from fully trusted sources until the fix is applied.

If using trusted packages and archives - the only impact to this is updating zarf binary or SDK package versions. Previously created packages do not need to be rebuilt.

### Who is affected

- Any user of affected Zarf versions who processes packages from untrusted or semi-trusted sources. This includes packages received via file transfer, downloaded from registries, or shared across organizational boundaries. This includes use of the `zarf tools archiver decompress` functionality on generic archives.

- Any SDK consumers of Zarf for the affected versions who utilize package load or archive operations. 

### What is the risk

A malicious Zarf package or archive could create symlinks pointing to arbitrary locations on the filesystem. This could lead to unauthorized file reads, file overwrites, or in some scenarios, code execution on the system performing the extraction in the event a file on the system is both overwritten and executed. This vulnerability does not introduce an execution path explicitly.

### Mitigating Factors

If developers only process trusted packages and/or trusted archives (with `zarf tools archiver decompress), the risk is low. 

### Details

The archive extraction code in src/pkg/archive/archive.go creates symlinks from archive entries without validating that the symlink target resolves within the extraction destination directory. This affects all three extraction handler functions:

1. defaultHandler (on line 320): Joins `dst` with `f.LinkTarget`, but does not verify the resolved path stays under `dst`. This means that a LinkTarget of `"../../../../etc/shadow"` would resolve outside the destination after `filepath.Join`.
2. stripHandler (on line 342): Passes `f.LinkTarget` verbatim to `os.Symlink`.
3. filterHandler (on line 370): Similar to `defaultHandler`, the code joins but does not validate the `LinkTarget`.

The vulnerability is a symlink variant of the "Zip Slip" class (CVE-2[PII_REDACTED]). An attacker constructs a Zarf package containing an archive entry with a malicious `f.LinkTarget`. When the package is extracted, `os.Symlink` creates a symlink pointing outside the extraction root. A subsequent archive entry targeting the same name can then read or write through the symlink to an arbitrary location on the filesystem.

### PoC

<details>
<summary>Proof of Concept</summary>
You may want to follow through these steps inside of a disposable environment (container, VM):

```bash
Reproduction via zarf tools archiver decompress (simplest)

This demonstrates the vulnerability using the defaultHa