Skip to content

Potential fix for code scanning alert no. 7: Arbitrary file access during archive extraction ("Zip Slip") - #15

Merged
ShadowDara merged 1 commit into
mainfrom
alert-autofix-7
Sep 13, 2026
Merged

ShadowDara merged 1 commit into
mainfrom
alert-autofix-7

Conversation

@ShadowDara

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/ShadowDara/finder/security/code-scanning/7

General fix: when extracting archive entries, canonicalize the destination root and each candidate output path, then verify each candidate stays under the root using a robust relative-path check (filepath.Rel) before any filesystem operation.

Best targeted fix in internal/bt/gitrepo/gitrepo.go (inside restoreZip):

  • Compute rootAbs once after creating destination.
  • For each entry:
    • Keep existing name normalization and basic unsafe-name checks.
    • Build target and resolved absolute paths.
    • Replace prefix-based containment logic with:
      • rel, err := filepath.Rel(rootAbs, resolved)
      • reject if rel == ".." or starts with ".."+separator or is absolute.
  • Use rootAbs instead of recalculating Abs(destination) each iteration.

No new dependencies are required; existing imports are sufficient.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ring archive extraction ("Zip Slip")

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ShadowDara
ShadowDara marked this pull request as ready for review September 13, 2026 20:48
@ShadowDara
ShadowDara merged commit d4c83e4 into main Sep 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant