GitHub Security Advisory: GHSA-jqc5-w2xx-5vq4
Package: github.com/theupdateframework/go-tuf/v2 (GO)
Severity: MODERATE (CVSS 4.7)
CWE: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Vulnerable versions: < 2.4.1
Patched in: 2.4.1

Summary: go-tuf Path Traversal in TAP 4 Multirepo Client Allows Arbitrary File Write via Malicious Repository Names

Details:
# Security Vulnerability: Path Traversal in TAP 4 Multirepo Client

## Summary

go-tuf's TAP 4 Multirepo Client uses the map file repository name string (`repoName`) as a filesystem path component when selecting the local metadata cache directory. If an application accepts a map file from an untrusted source, an attacker can supply a `repoName` containing traversal (e.g., `../escaped-repo`) and cause go-tuf to create directories and write the root metadata file outside the intended `LocalMetadataDir` cache base, within the running process's filesystem permissions.

## Affected Component

| Field | Value |
|-------|-------|
| **File** | `metadata/multirepo/multirepo.go` |
| **Function** | `(*MultiRepoClient) initTUFClients() error` |
| **Callsite** | `metadataDir := filepath.Join(client.Config.LocalMetadataDir, repoName)` (around line 129 at the pinned commit) |

## Impact

When the TAP 4 map file content is attacker-controlled, this enables arbitrary file write relative to the process permissions (via metadata persistence during client initialization). This can be used to overwrite files writable by the process (for example, configuration files in writable directories) and may enable further compromise depending on the deployment environment.

> **Note:** Exploitability is deployment-dependent. If the map file is always local and trusted (not attacker-controlled), this reduces to a misconfiguration risk rather than a remotely triggerable issue.

## Attacker Model

- Attacker can cause the application to load a TAP 4 map file whose `repositories` keys are attacker-controlled (for example: fetched from a URL, supply-chain substituted, or otherwise attacker-influenced input).
- Local caching is enabled (`DisableLocalCache=false`) and the configured `LocalMetadataDir` is writable by the running process.

**Claim Ceiling:** HIGH when the map file is attacker-controlled; if the map file is always local and trusted, this is closer to a configuration footgun and likely lands as MEDIUM/LOW.

| Field | Value |
|-------|-------|
| **Affected Versions** | ≤ 2.4.0 |
| **Verified On** | Commit `bde5f18dc95dfac365fc452ee4e278e5fd66d4b4` (tag v2.4.0) |

> **Note:** First affected version has not been bisected.

## Reproduction

Attachments include `poc.zip` with:
- `canonical.log` (contains `[CALLSITE_HIT]`, `[PROOF_MARKER]`)
- `control.log` (contains `[CALLSITE_HIT]`, `[NC_MARKER]`, does not contain `[PROOF_MARKER]`)
- `fix.patch` (minimal validation sketch)

**Expected:** Multirepo repository names are treated as identifiers; a TAP 4 map file containing traversal or absolute paths is rejected (or safely normalized so that all writes stay under `LocalMetadataDir`).

**Actual:** A traversal `repoName` escapes `LocalMetadataDir` and go-tuf persists `root.json` under the escaped path during initialization.

### Run Local Repro

```bash
rm -rf _poc
mkdir -p _poc
unzip -q -o poc.zip -d _poc
cd _poc/poc
make canonical
make control
```

## Workarounds

1. Treat TAP 4