test(extract): cover path-traversal helpers - #1059
Open
devsy-app[bot] wants to merge 4 commits into
Open
Conversation
Add direct unit tests for pkg/extract's security-boundary helpers (withinDir, resolveLinkTarget, resolveRelativePath StripLevels branches, validateLinkTarget) that previously had only indirect coverage via Extract.
✅ Deploy Preview for images-devsy-sh canceled.
|
✅ Deploy Preview for devsydev canceled.
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 19 |
| Duplication | 0 |
AI Reviewer: run a review on demand. To trigger the first review automatically, go to your organization or repository integration settings. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
Signed-off-by: Samuel K <skevetter@pm.me>
skevetter
marked this pull request as ready for review
August 17, 2026 05:47
Signed-off-by: Samuel K <skevetter@pm.me>
skevetter
force-pushed
the
pkg-container/extract-security-tests
branch
from
August 17, 2026 06:18
e8df7dc to
7bf95d3
Compare
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.
Package reviewed
pkg/extract(Docker/OCI image extraction — tar/gzip/zip path-traversal boundary).Issue found
The package's security-critical helpers —
withinDir,resolveLinkTarget,resolveRelativePath(incl. itsStripLevelsbranches), andvalidateLinkTarget— are the boundary that blocks tar/zip-slip (path traversal, symlink traversal, hard-link traversal). They were only exercised indirectly through end-to-endExtract/UnzipFoldertests, with no direct coverage of their edge cases (sibling-prefix escapes, the exact-dest boundary, parent-dir rejection, absolute vs relative link targets, and theStripLevelsstrip-beyond-depth fallback). A regression in any of these pure functions could silently weaken the extraction boundary while the indirect tests still passed.Change
Added
pkg/extract/path_test.gowith direct, table-driven unit tests (no behavioral change to production code):TestWithinDir— nested inside, exactly dest, deep inside, sibling-prefix outside (dest_evil), unrelated outside, parent dir.TestResolveLinkTarget— absolute target preserved, relative parent (../target), relative sibling.TestResolveRelativePath_StripLevels— no strip, strip one/two levels, strip beyond depth (remainder kept), strip to final segment.TestValidateLinkTarget— symlink inside allowed, symlink traversal blocked, hard-link traversal blocked.Verification performed
task cli:format— clean (gofmt/gci/gofumpt).task cli:lint:ci—0 issues(new-from-patch against origin/main).task cli:test—pkg/extractpasses (ok github.com/devsy-org/devsy/pkg/extract).pkg/git(TestRepoCloneFromInfoHelper), the documented known pre-existing failure on origin/main (stale LFS-config assertion), unrelated to this change — this PR does not touchpkg/git.go.mod/go.sumchurn fromcli:tidywas reverted so the diff contains only the new test file.This PR was created by an AI agent as part of an automated daily package review job.