Repository navigation
Enforce IsLocal and prefix check in expansionx validatePath - #41589
Conversation
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR hardens validatePath in expansionx/download.go to remediate a CodeQL go/zipslip alert by validating archive entry paths with filepath.IsLocal and an explicit destination prefix check. It also adds relevant edge cases to TestValidatePath in download_test.go.
🔍 General Feedback
- The combination of
filepath.IsLocal(onfilepath.FromSlash(filename)) andstrings.HasPrefix(cleanPath, cleanDest+string(filepath.Separator))is idiomatic and properly prevents directory traversal while satisfying static analysis barrier guards. - Explicit handling of
.entries preserves compatibility with JARs created viapackJar(".", ...).
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41589 +/- ##
============================================
- Coverage 58.01% 58.00% -0.01%
Complexity 2842 2842
============================================
Files 1210 1210
Lines 173145 173148 +3
Branches 2330 2330
============================================
- Hits 100443 100436 -7
- Misses 69990 69997 +7
- Partials 2712 2715 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @shunping for label go. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
shunping
left a comment
There was a problem hiding this comment.
Thanks for hardening the code here!
Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:
CodeQL/zizmor) onmasterwithout altering intended public API or workflow semanticsIf you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)
Summary
Resolves open
CodeQLgo/zipslip(High / error, alert#1912) insdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:validatePathinexpansionx/download.gousingfilepath.IsLocal(afterfilepath.FromSlash) and a directstrings.HasPrefix(cleanPath, cleanDest+string(filepath.Separator))boundary check (with explicit handling for root.entries produced bypackJar(".", ...)), replacing the compoundfilepath.Relcheck that did not satisfy CodeQL'sgo/zipslipbarrier guards.TestValidatePathindownload_test.goto cover directory entries (META-INF/,./), filenames containing non-traversal double dots (Foo..Bar.class), absolute paths (/etc/passwd), and empty paths.Verification
gofmt&go vet ./go/pkg/beam/core/runtime/xlangx/expansionx/...go test -v ./go/pkg/beam/core/runtime/xlangx/expansionx/...