Skip to content

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

Merged
ShadowDara merged 1 commit into
mainfrom
alert-autofix-6
Sep 9, 2026
Merged

ShadowDara merged 1 commit into
mainfrom
alert-autofix-6

Conversation

@ShadowDara

Copy link
Copy Markdown
Owner

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

To fix Zip Slip safely, validate each archive entry name before any filesystem operation, then continue using the existing resolved-within-root check as defense in depth.

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

  • Add early validation of file.Name:
    • reject empty names
    • normalize with filepath.Clean(filepath.FromSlash(file.Name))
    • reject absolute/volume-qualified paths (filepath.IsAbs(...) and filepath.VolumeName(...) != "")
    • reject any .. traversal segments using segment-aware checks (not just substring)
  • Use the cleaned relative path for filepath.Join(destination, cleanedName).
  • Keep existing absolute containment check (resolved under root) intact.

This addresses both CodeQL variants at line 420 and 427 because tainted, unvalidated names no longer reach directory creation or file creation paths.

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 9, 2026 15:01
@ShadowDara
ShadowDara merged commit 57ada62 into main Sep 9, 2026
5 of 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