Skip to content

fix: sanitize inspect output path#4793

Merged
AustinAbro321 merged 2 commits intomainfrom
sanitaize-name-path
Apr 8, 2026
Merged

fix: sanitize inspect output path#4793
AustinAbro321 merged 2 commits intomainfrom
sanitaize-name-path

Conversation

@AustinAbro321
Copy link
Copy Markdown
Member

@AustinAbro321 AustinAbro321 commented Apr 7, 2026

Description

This prevents package name that's been edited to go an arbitrary directory from leaving the cwd when using zarf package inspect definition or zarf package inspect sbom

Checklist before merging

Signed-off-by: Austin Abro <austinabro321@gmail.com>
@AustinAbro321 AustinAbro321 requested review from a team as code owners April 7, 2026 20:03
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 7, 2026

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 9c9f43e
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/69d68c59c9f15b0008bf4526

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pkg/packager/create.go 0.00% 2 Missing ⚠️
src/cmd/package.go 50.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/pkg/packager/layout/package.go 65.01% <100.00%> (+0.13%) ⬆️
src/cmd/package.go 38.08% <50.00%> (ø)
src/pkg/packager/create.go 55.31% <0.00%> (-0.60%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dgershman
dgershman previously approved these changes Apr 8, 2026
Copy link
Copy Markdown
Contributor

@dgershman dgershman left a comment

Choose a reason for hiding this comment

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

Code & Security Review

Critical Issues

None.

Security Review

Strengths:

  • Correctly fixes a path traversal vulnerability where a maliciously crafted package name (e.g., ../../etc/evil) could write SBOM or documentation files outside the intended output directory.
  • filepath.Base() is the right mitigation — it strips all directory components, preventing traversal while preserving the actual name.
  • Fix is applied consistently across all three affected call sites:
    • src/cmd/package.go — SBOM inspect output path
    • src/cmd/package.go — documentation inspect output path
    • src/pkg/packager/create.go — SBOM output during package create

Minor Observation:

  • filepath.Base("") returns ".", which would produce an output path like outputDir/. — but an empty package name is an edge case that would likely be caught by other validation. Not a blocking issue.
  • No test is added for the sanitization. A unit test verifying that a name like ../../traversal is sanitized to traversal would strengthen confidence, but the fix itself is straightforward enough that this isn't blocking.

Code Quality

  • Clean, minimal change with appropriate comments explaining the "why."
  • No unnecessary refactoring.

Summary Table

Priority Issue
🟢 Green Consider adding a test for path traversal sanitization
🟢 Green Edge case: empty package name produces "." via filepath.Base("") (unlikely in practice)

Recommendation: Approve — the fix is correct, minimal, and consistently applied across all affected paths.

@AustinAbro321 AustinAbro321 added this pull request to the merge queue Apr 8, 2026
@AustinAbro321 AustinAbro321 removed this pull request from the merge queue due to a manual request Apr 8, 2026
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Copy link
Copy Markdown
Member

@brandtkeller brandtkeller left a comment

Choose a reason for hiding this comment

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

lgtm

@AustinAbro321 AustinAbro321 added this pull request to the merge queue Apr 8, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 8, 2026
@AustinAbro321 AustinAbro321 added this pull request to the merge queue Apr 8, 2026
Merged via the queue into main with commit abd00af Apr 8, 2026
32 checks passed
@AustinAbro321 AustinAbro321 deleted the sanitaize-name-path branch April 8, 2026 18:53
@github-project-automation github-project-automation Bot moved this to Done in Zarf Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants