Skip to content

go-archives: symlink extraction attack tests - #9657

Merged
taylorsilva merged 1 commit into
concourse:masterfrom
Pix4D:pci-4898-symlink-extraction-tests-upstream
Jul 28, 2026
Merged

taylorsilva merged 1 commit into
concourse:masterfrom
Pix4D:pci-4898-symlink-extraction-tests-upstream

Conversation

@aliculPix4D

Copy link
Copy Markdown
Contributor

Summary

Add regression tests that exercise classic symlink-based tar extraction attacks against tarfs.Extract.

These cover the attack shapes that matter in practice:

  • directory symlink → write a file through it (absolute and ../ relative targets)
  • file symlink → overwrite the same path with file contents (absolute and ../ relative targets)

In each case, extraction must fail, and nothing may appear outside the destination directory.

Why

os.Root is what makes this safe after #9601. That change intentionally relaxed the overly strict breakout checks from #9486 so legitimate intra-repo relative symlinks (especially on Windows) work again, while still blocking writes that would escape the extraction root.

Without tests like these, it is easy to “simplify” extraction later and accidentally undo that protection — for example, by reverting #9601 or dropping os.Root without understanding why it is there.

These specs are also concrete evidence that the security issue addressed in #9486 remains fixed under the #9601 approach: escaping symlinks may be created in some cases, but following them to write outside the destination is refused.

// will not be found. The directory must exist, so that the lookup fails
// identically on every platform. GinkgoT().Setenv will restore PATH after
// the spec.
GinkgoT().Setenv("PATH", GinkgoT().TempDir())

@aliculPix4D aliculPix4D Jul 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I originally wrote in our Pix4D fork PR: Pix4D#832 (comment)

I am more than tempted to open a 2nd PR to run the same tests on Unix when tar is on the path.

They must behave the same with tar :) If these test fail with tar (reminder: a failing test means that you are vulnerable to the attack) it means you have a security issue with tar :)

Lets first see how this PR review goes :)

@aliculPix4D

Copy link
Copy Markdown
Contributor Author

@odormond @marco-m-pix4d FYI same as the PR in our fork..

@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Jul 27, 2026
@taylorsilva
taylorsilva merged commit 2492d38 into concourse:master Jul 28, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Jul 28, 2026
@aliculPix4D
aliculPix4D deleted the pci-4898-symlink-extraction-tests-upstream branch July 29, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants