Skip to content

Enforce IsLocal and prefix check in expansionx validatePath - #41589

Merged
shunping merged 1 commit into
masterfrom
codescan/go-expansionx-zipslip
Nov 25, 2026
Merged

shunping merged 1 commit into
masterfrom
codescan/go-expansionx-zipslip

Conversation

@derrickaw

Copy link
Copy Markdown
Collaborator

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:

  • The PR remediates confirmed, live Code Scanning finding(s) (CodeQL / zizmor) on master without altering intended public API or workflow semantics
  • The fix is minimal, idiomatic, and avoids suppressing alerts or masking underlying defects
  • Relevant unit tests, linters, and CI checks have been verified

If 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 CodeQL go/zipslip (High / error, alert #1912) in sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:

  • Harden validatePath in expansionx/download.go using filepath.IsLocal (after filepath.FromSlash) and a direct strings.HasPrefix(cleanPath, cleanDest+string(filepath.Separator)) boundary check (with explicit handling for root . entries produced by packJar(".", ...)), replacing the compound filepath.Rel check that did not satisfy CodeQL's go/zipslip barrier guards.
  • Expand TestValidatePath in download_test.go to 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/...

@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 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 (on filepath.FromSlash(filename)) and strings.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 via packJar(".", ...).

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.00%. Comparing base (caa0e29) to head (8df65c3).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...kg/beam/core/runtime/xlangx/expansionx/download.go 85.71% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
go 29.20% <85.71%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@github-actions github-actions Bot added go core size/s S: 10-49 lines changed labels Nov 23, 2026
@derrickaw derrickaw added the ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review label Nov 23, 2026
@derrickaw
derrickaw marked this pull request as ready for review November 23, 2026 17:37
@derrickaw derrickaw removed the ready-for-human Draft PR with all checks passing and all review comments resolved, ready for human review label Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping for label go.
Backup reviewer: jrmccluskey (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

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 assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@shunping shunping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for hardening the code here!

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.

2 participants