Skip to content

fix(bundler): harden filepath.Join with SafeJoin for path-traversal protection#578

Merged
lockwobr merged 1 commit intomainfrom
fix/safejoin
Apr 17, 2026
Merged

fix(bundler): harden filepath.Join with SafeJoin for path-traversal protection#578
lockwobr merged 1 commit intomainfrom
fix/safejoin

Conversation

@lockwobr
Copy link
Copy Markdown
Contributor

@lockwobr lockwobr commented Apr 14, 2026

Summary

Harden filepath.Join calls in bundler production code with deployer.SafeJoin for path-traversal protection, and exclude goconst from test file linting.

Motivation / Context

CodeQL flagged several filepath.Join calls during PR #527 review where the second argument could originate from user input. SafeJoin validates that joined paths
stay within the base directory, preventing path traversal. The goconst exclusion removes unnecessary ceremony — repeated test strings don't benefit from constant
extraction.

Closes: #574
Related: #527
Branched off of: #575

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Build/CI/tooling

Component(s) Affected

  • CLI (cmd/aicr, pkg/cli)
  • API server (cmd/aicrd, pkg/api, pkg/server)
  • Recipe engine / data (pkg/recipe)
  • Bundlers (pkg/bundler, pkg/component/*)
  • Collectors / snapshotter (pkg/collector, pkg/snapshotter)
  • Validator (pkg/validator)
  • Core libraries (pkg/errors, pkg/k8s)
  • Docs/examples (docs/, examples/)
  • Other: ____________

Implementation Notes

Testing

# Commands run (prefer `make qualify` for non-trivial changes)
make qualify

Risk Assessment

  • Low — Isolated change, well-tested, easy to revert
  • Medium — Touches multiple components or has broader impact
  • High — Breaking change, affects critical paths, or complex rollout

Rollout notes:

Checklist

  • Tests pass locally (make test with -race)
  • Linter passes (make lint)
  • I did not skip/disable tests to make CI green
  • I added/updated tests for new functionality
  • I updated docs if user-facing behavior changed
  • Changes follow existing patterns in the codebase
  • Commits are cryptographically signed (git commit -S) — GPG signing info

@lockwobr lockwobr self-assigned this Apr 14, 2026
@lockwobr lockwobr requested review from a team as code owners April 14, 2026 23:03
@lockwobr lockwobr linked an issue Apr 15, 2026 that may be closed by this pull request
yuanchen8911
yuanchen8911 previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@yuanchen8911 yuanchen8911 left a comment

Choose a reason for hiding this comment

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

A couple of minor issues.

Consider adding a regression test for the Helm external-data path.

# File Line Severity Description
1 pkg/bundler/checksum/checksum.go 88, 154 minor GetChecksumFilePath and CountEntries still use filepath.Join — no real traversal risk (constant second arg) but inconsistent with the hardening pattern. Converting would require a signature change to (string, error).
2 pkg/bundler/bundler.go ~830 minor Unsafe data file path in attestation silently skipped (continue + Debug log) instead of failing. User opted into --attest, so silently omitting a file from attestation weakens integrity. Should at minimum log at Warn, or arguably fail like the other SafeJoin calls.

@yuanchen8911 yuanchen8911 self-requested a review April 15, 2026 14:32
@yuanchen8911
Copy link
Copy Markdown
Contributor

Note: the double copyDataFiles call for the helm deployer (buildDeployer copies data pre-generation, then runDeployer copies again) is a regression from the base branch (#575), not introduced by this PR. os.CopyFS fails with fs.ErrExist on the second call, breaking --deployer helm --data <dir>. See the review on #575 for details.

Copy link
Copy Markdown
Contributor

@yuanchen8911 yuanchen8911 left a comment

Choose a reason for hiding this comment

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

the regression introduced by #575 needs to be fixed first.

@yuanchen8911 yuanchen8911 self-requested a review April 15, 2026 16:33
@yuanchen8911 yuanchen8911 dismissed their stale review April 15, 2026 16:37

regression in PR #575 should be fixed.

Copy link
Copy Markdown
Contributor

@yuanchen8911 yuanchen8911 left a comment

Choose a reason for hiding this comment

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

, #575 adds the second copyDataFiles(dir) call in runDeployer() after Helm already copied the same external --data files in buildDeployer(). That needs to be fixed.

Copy link
Copy Markdown
Contributor

@yuanchen8911 yuanchen8911 left a comment

Choose a reason for hiding this comment

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

#575 adds the second copyDataFiles(dir) call in runDeployer() after Helm already copied the same external --data files in buildDeployer(). That needs to be fixed.

@lockwobr lockwobr force-pushed the feat/deployer-interface branch 2 times, most recently from 8e9c264 to c93bfd9 Compare April 15, 2026 18:38
@github-actions github-actions bot added size/L and removed size/M labels Apr 15, 2026
@lockwobr lockwobr requested a review from yuanchen8911 April 15, 2026 18:42
Copy link
Copy Markdown
Contributor

@ArangoGutierrez ArangoGutierrez left a comment

Choose a reason for hiding this comment

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

SafeJoin hardening looks correct overall. The test for path traversal rejection in helm_test.go is solid. Two items from Mark's review still need addressing:

  1. The attestation data file loop (former line ~830) now silently continues on SafeJoin failure with a Debug log, but the user opted into --attest -- silently omitting a file weakens integrity. Should at minimum be Warn, arguably fail.

  2. GetChecksumFilePath and CountEntries still use filepath.Join. The inline comments explaining why are fine, but worth confirming Mark is OK with that rationale.

Also note the dependency on #575 for the copyDataFiles flow -- merge order matters here.

@lockwobr lockwobr force-pushed the feat/deployer-interface branch 2 times, most recently from fa30a50 to ec451a2 Compare April 16, 2026 17:21
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@lockwobr has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 33 minutes and 59 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 33 minutes and 59 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0c1c341b-a358-4959-97b3-5360f6d64a0f

📥 Commits

Reviewing files that changed from the base of the PR and between b82af6f and 385b688.

📒 Files selected for processing (7)
  • .golangci.yaml
  • pkg/bundler/attestation/binary.go
  • pkg/bundler/bundler.go
  • pkg/bundler/checksum/checksum.go
  • pkg/bundler/deployer/helm/helm.go
  • pkg/bundler/deployer/helm/helm_test.go
  • pkg/bundler/verifier/verifier.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/safejoin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Base automatically changed from feat/deployer-interface to main April 16, 2026 23:51
@github-actions
Copy link
Copy Markdown

@lockwobr this PR now has merge conflicts with main. Please rebase to resolve them.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

Coverage Report ✅

Metric Value
Coverage 75.1%
Threshold 70%
Status Pass
Coverage Badge
![Coverage](https://img.shields.io/badge/coverage-75.1%25-green)

Merging this branch changes the coverage (3 decrease, 2 increase)

Impacted Packages Coverage Δ 🤖
github.com/NVIDIA/aicr/pkg/bundler 63.00% (-2.00%) 👎
github.com/NVIDIA/aicr/pkg/bundler/attestation 69.12% (-0.29%) 👎
github.com/NVIDIA/aicr/pkg/bundler/checksum 85.07% (+1.98%) 👍
github.com/NVIDIA/aicr/pkg/bundler/deployer/helm 88.08% (+1.17%) 👍
github.com/NVIDIA/aicr/pkg/bundler/verifier 61.98% (-1.81%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/NVIDIA/aicr/pkg/bundler/attestation/binary.go 88.89% (-4.86%) 18 (+2) 16 (+1) 2 (+1) 👎
github.com/NVIDIA/aicr/pkg/bundler/bundler.go 59.79% (-2.50%) 378 (+20) 226 (+3) 152 (+17) 👎
github.com/NVIDIA/aicr/pkg/bundler/checksum/checksum.go 85.07% (+1.98%) 67 (-4) 57 (-2) 10 (-2) 👍
github.com/NVIDIA/aicr/pkg/bundler/deployer/helm/helm.go 88.08% (+1.17%) 193 (+2) 170 (+4) 23 (-2) 👍
github.com/NVIDIA/aicr/pkg/bundler/verifier/verifier.go 58.03% (-2.08%) 193 (+10) 112 (+2) 81 (+8) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Copy link
Copy Markdown
Contributor

@yuanchen8911 yuanchen8911 left a comment

Choose a reason for hiding this comment

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

LGTM. On the current rebased head, the previously discussed #575 issue is addressed for purposes of reviewing this PR, and I don’t have any remaining blocking findings on the SafeJoin hardening changes.

@yuanchen8911
Copy link
Copy Markdown
Contributor

Confirmed on the rebased head that the copyDataFiles issue discussed from #575 is no longer a blocker for reviewing this PR. The SafeJoin hardening here looks good to me, and the PR LGTM from a code-review perspective.

@lockwobr lockwobr merged commit 6f4ec0e into main Apr 17, 2026
24 checks passed
@lockwobr lockwobr deleted the fix/safejoin branch April 17, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundler cleanup: SafeJoin hardening and goconst test config

3 participants