Skip to content

fix: prevent tar-slip path traversal in archive extraction#5979

Merged
xavpaice merged 2 commits into
mainfrom
tar-fix
Jul 20, 2026
Merged

fix: prevent tar-slip path traversal in archive extraction#5979
xavpaice merged 2 commits into
mainfrom
tar-fix

Conversation

@xavpaice

Copy link
Copy Markdown
Member

What this PR does / why we need it:

Add a shared SafeArchivePath helper in pkg/archiveutil that validates tar entry paths before writing them. Use it in all hand-rolled tar extractors (pkg/archives, pkg/util, pkg/archiveutil, pkg/image, pkg/upstream) and add regression tests for dot-dot and absolute path traversal attempts.

Which issue(s) this PR fixes:

Does this PR require a test?

Does this PR require a release note?

NONE

Does this PR require documentation?

Add a shared SafeArchivePath helper in pkg/archiveutil that validates

tar entry paths before writing them. Use it in all hand-rolled tar

extractors (pkg/archives, pkg/util, pkg/archiveutil, pkg/image,

pkg/upstream) and add regression tests for dot-dot and absolute path

traversal attempts.
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown

Security Review

A symlink-based traversal gap remains when extraction writes into a destination tree that already contains symlinks.

Reviews (1): Last reviewed commit: "fix: prevent tar-slip path traversal in ..." | Re-trigger Greptile

Comment thread pkg/archiveutil/tgz.go
SafeArchivePath now walks each parent component of the target path

and rejects any existing symlink as a potential escape. This prevents

an archive entry like link/pwned from being written outside the

extraction root when dest/link points to a directory outside the root.

Add a regression test that creates a symlink in the destination and

verifies the entry is rejected.
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "fix: detect symlink escapes in archive e..." | Re-trigger Greptile

@xavpaice
xavpaice merged commit 67a415c into main Jul 20, 2026
95 checks passed
@xavpaice
xavpaice deleted the tar-fix branch July 20, 2026 20:31
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.

2 participants