Skip to content

fix(container): prevent path traversal in untar test helper - #172

Merged
robmry merged 2 commits into
docker:mainfrom
mdelapenya:fix/container-untar-zip-slip
Oct 27, 2026
Merged

robmry merged 2 commits into
docker:mainfrom
mdelapenya:fix/container-untar-zip-slip

Conversation

@mdelapenya

Copy link
Copy Markdown
Member

What does this PR do?

It makes the untar test helper in container/files_test.go write through an os.Root scoped to the destination dir, so entries like ../evil or /evil fail instead of escaping it. It also adds TestUntar_rejectsPathTraversal to cover those cases.

Why is it important?

Sonar flags it as Zip Slip. It's only test code, but I'd like to have it clean before the next release.

Related issues

🤖 Generated with Claude Code

🤖 Written assisted by my Claude

Scope all filesystem writes in the untar test helper to an os.Root on
the destination directory, so archive entries escaping it are rejected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mdelapenya mdelapenya added the bug Something isn't working label Oct 26, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T20:26:08.607188Z 9241b63 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9241b633a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread container/files_test.go Outdated
@mdelapenya
mdelapenya enabled auto-merge (squash) October 26, 2026 20:30
@mdelapenya
mdelapenya requested a balanced review from Copilot October 27, 2026 06:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review identified no blocking issues in the focused test-helper changes; tests were not executed.

No open issues 🎉

What changed in this PR

This PR hardens the container tests’ untar helper against path traversal by confining archive extraction to the destination directory.

Changes:

  • Uses os.Root for directory creation and file writes during extraction.
  • Adds regression tests for parent-directory traversal and absolute paths.
  • Closes the output file if copying archive contents fails.
File Description
container/​files_test.go Confines extraction to the destination, adds traversal tests, and improves file cleanup.

Review effort: Balanced

os.Root.OpenFile rejects permission bits outside 0o777, so archives with
setuid, setgid or sticky bits could no longer be extracted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@robmry
robmry disabled auto-merge October 27, 2026 07:47
@robmry
robmry enabled auto-merge (squash) October 27, 2026 07:50
@robmry
robmry disabled auto-merge October 27, 2026 07:56
@robmry
robmry merged commit d91c985 into docker:main Oct 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants