Skip to content

Resolve zip slip + fix leaking file handles - #41183

Closed
jrmccluskey wants to merge 1 commit into
apache:masterfrom
jrmccluskey:zipSlipSlide
Closed

jrmccluskey wants to merge 1 commit into
apache:masterfrom
jrmccluskey:zipSlipSlide

Conversation

@jrmccluskey

Copy link
Copy Markdown
Contributor

The initial zip slip fix in expansionx (#39638,) was not solved in a way the code scanner liked, so this reformats the fix + fixes the use of defer in extractJar to avoid leaking file handles until large JARs are returned.

@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 updates validatePath in expansionx to use filepath.IsLocal and a cleaned prefix check recognized by static analysis scanners for Zip Slip protection, and refactors extractJar to properly close the archive reader and per-entry file handles instead of deferring closures until function exit. The changes are well-structured and accompanied by thorough unit tests covering path traversal cases and file descriptor exhaustion.

🔍 General Feedback

  • Scoping file handle lifecycles into extractZipEntry and explicitly checking df.Close() write errors is a solid improvement over deferring inside the extraction loop.
  • Combining filepath.IsLocal with strings.HasPrefix(destPath, cleanDest+string(filepath.Separator)) cleanly satisfies CodeQL's go/zipslip sanitizer requirements while preserving defense-in-depth.

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

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.62069% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.63%. Comparing base (e9705e2) to head (0588391).
⚠️ Report is 192 commits behind head on master.

Files with missing lines Patch % Lines
...kg/beam/core/runtime/xlangx/expansionx/download.go 58.62% 6 Missing and 6 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41183      +/-   ##
============================================
+ Coverage     57.61%   57.63%   +0.01%     
  Complexity     2617     2617              
============================================
  Files          1209     1209              
  Lines        171890   171930      +40     
  Branches       2163     2163              
============================================
+ Hits          99036    99088      +52     
+ Misses        70187    70171      -16     
- Partials       2667     2671       +4     
Flag Coverage Δ
go 29.22% <58.62%> (+0.05%) ⬆️

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/m M: 50-249 lines changed labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @lostluck for label go.
Backup reviewer: shunping (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).

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @lostluck @shunping

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @kennknowles added as fallback since no labels match configuration
Backup reviewer: chamikaramj (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.

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)

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

Looks like some changes in this PR has been resolved in #41589 and merged. Could you sync with master? Thanks!

@jrmccluskey

Copy link
Copy Markdown
Contributor Author

Looks like some changes in this PR has been resolved in #41589 and merged. Could you sync with master? Thanks!

Looks like that PR resolved it, this is no longer necessary. That being said, there's no reason this PR doing the same thing should have sat for two weeks without getting reviewed.

@shunping

Copy link
Copy Markdown
Collaborator

Looks like some changes in this PR has been resolved in #41589 and merged. Could you sync with master? Thanks!

Looks like that PR resolved it, this is no longer necessary. That being said, there's no reason this PR doing the same thing should have sat for two weeks without getting reviewed.

My apologies—this slipped off my radar.

When I compared the two PRs yesterday, I noticed there's a change to extractJar here that isn't in #41589. Do we still need that fix? @jrmccluskey

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