Skip to content

test(extract): cover path-traversal helpers - #1059

Open
devsy-app[bot] wants to merge 4 commits into
mainfrom
pkg-container/extract-security-tests
Open

test(extract): cover path-traversal helpers#1059
devsy-app[bot] wants to merge 4 commits into
mainfrom
pkg-container/extract-security-tests

Conversation

@devsy-app

@devsy-app devsy-app Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

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. its StripLevels branches), and validateLinkTarget — are the boundary that blocks tar/zip-slip (path traversal, symlink traversal, hard-link traversal). They were only exercised indirectly through end-to-end Extract/UnzipFolder tests, with no direct coverage of their edge cases (sibling-prefix escapes, the exact-dest boundary, parent-dir rejection, absolute vs relative link targets, and the StripLevels strip-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.go with 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:ci0 issues (new-from-patch against origin/main).
  • task cli:testpkg/extract passes (ok github.com/devsy-org/devsy/pkg/extract).
  • The only failing package is pkg/git (TestRepoCloneFromInfoHelper), the documented known pre-existing failure on origin/main (stale LFS-config assertion), unrelated to this change — this PR does not touch pkg/git.
  • go.mod/go.sum churn from cli:tidy was 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.

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.
@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 7bf95d3
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a82a7d0702834000898d42f

@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 7bf95d3
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a82a7d03a764a0008a222ea

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 19 complexity · 0 duplication

Metric Results
Complexity 19
Duplication 0

View in Codacy

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.

Run reviewer

TIP This summary will be updated as you push new changes.

@skevetter
skevetter marked this pull request as ready for review August 17, 2026 05:47
Signed-off-by: Samuel K <skevetter@pm.me>
@skevetter
skevetter force-pushed the pkg-container/extract-security-tests branch from e8df7dc to 7bf95d3 Compare August 17, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant