Skip to content

fix(solutils): reject path traversal in downloadProgramArtifacts#22278

Open
genisis0x wants to merge 1 commit intosmartcontractkit:developfrom
genisis0x:fix/zip-slip-21003
Open

fix(solutils): reject path traversal in downloadProgramArtifacts#22278
genisis0x wants to merge 1 commit intosmartcontractkit:developfrom
genisis0x:fix/zip-slip-21003

Conversation

@genisis0x
Copy link
Copy Markdown

Description

Fixes #21003.

downloadProgramArtifacts in deployment/utils/solutils/artifacts.go extracted archive entries by joining the target directory with filepath.Base(header.Name). That sanitization is enough for benign payloads such as ../etc/passwd, which collapses to passwd, but a header name of just .. made filepath.Join(targetDir, "..") resolve to the parent of the target directory, allowing extraction to escape.

Fix

In downloadProgramArtifacts:

  • filepath.Clean + filepath.Base the entry name and refuse . / .. / empty / root entries explicitly.
  • Resolve the joined path with filepath.Abs and verify with filepath.Rel that it stays within targetDir. Anything that walks outside is rejected with a clear error.

Tests

TestDownloadProgramArtifacts_RejectsPathTraversal (in deployment/utils/solutils/artifacts_test.go) covers two classes:

Entry name Behaviour
.., ./.. Extraction returns an error (explicit reject)
../escape.so, ../../etc/passwd, /etc/passwd filepath.Base collapses to a safe name; the file lands inside tempDir and the parent directory is verified untouched (defense in depth)

The existing happy-path / 4xx-5xx / context-cancel tests continue to pass.

$ go test ./utils/solutils/... -count=1
ok  	github.com/smartcontractkit/chainlink/deployment/utils/solutils

Risk

Confined to one helper used by Solana artifact downloads. No behaviour change for valid archives. New rejections only fire for entry names that should never appear in legitimate artifacts.

`downloadProgramArtifacts` in deployment/utils/solutils/artifacts.go
extracted archive entries using only `filepath.Base(header.Name)` to
strip directory components. That is enough for benign names like
"../etc/passwd" (which collapses to "passwd"), but a name of just
".." caused `filepath.Join(targetDir, "..")` to resolve to the
parent of the target directory, allowing extraction to escape.

Harden the extractor:

  - filepath.Clean + filepath.Base the archive name and reject "."
    and "..".
  - resolve the joined path with filepath.Abs and verify it stays
    within targetDir using filepath.Rel; reject anything that walks
    out.

Add `TestDownloadProgramArtifacts_RejectsPathTraversal` covering the
explicit-rejection cases (`..`, `./..`) and the defense-in-depth
cases (`../foo.so`, `../../etc/passwd`, `/etc/passwd`) where the
benign filename is accepted but no file is allowed to land outside
`targetDir`.

Closes smartcontractkit#21003.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Validate extraction paths in downloadProgramArtifacts to prevent path traversal

1 participant