Feat/bounded tar extraction - #5
Merged
Merged
Conversation
Add a Feature Briefing section requiring a plain-English what/why/how summary to the user before starting any roadmap feature. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Unbounded io.Copy let a malicious layer fill the disk (tar bomb), and symlink/hardlink targets were never checked against the extraction root. Add an Extractor with per-entry and cumulative size caps via LimitReader, reject absolute paths and ".." components, and validate symlink/hardlink targets stay in-tree (treating absolute targets literally so they cannot re-root through filepath.Join). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why:
The extractor unpacked container image layers with an unbounded io.Copy, so a malicious or corrupted image could carry a tar bomb that inflates to fill the disk. Symlink and hardlink entries were also never validated against the extraction root, leaving a path-traversal hole. For a tool whose whole job is scanning untrusted images, both are unacceptable.
What changed:
Introduced an Extractor with configurable per-entry (FileSizeCap, default 512 MiB) and cumulative (TotalSizeCap, default 2 GiB) size caps, enforced via io.LimitReader.
Reject absolute paths and .. components before touching the filesystem.
Validate symlink/hardlink targets stay in-tree, treating absolute targets literally so they can't re-root through filepath.Join.
ExtractImage delegates to New().Untar(...) — no change to existing callers.
Added table-driven tests covering safe/rejected entries, size caps, and a multi-hop chained-symlink escape.
Verified: go test -race ./..., golangci-lint run, and govulncheck ./... all clean. No new dependencies.