Skip to content

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

Draft
eriknordmark wants to merge 1 commit into
masterfrom
alert-autofix-2389
Draft

Potential fix for code scanning alert no. 2389: Arbitrary file access during archive extraction ("Zip Slip")#6250
eriknordmark wants to merge 1 commit into
masterfrom
alert-autofix-2389

Conversation

@eriknordmark

Copy link
Copy Markdown
Contributor

Potential fix for https://github.com/lf-edge/eve/security/code-scanning/2389

To fix Zip Slip safely without changing intended behavior, validate every archive entry path before any filesystem operation. Build a helper that:

  1. Rejects empty names.
  2. Cleans the archive path (path.Clean).
  3. Rejects absolute paths and traversal (.. and /.. prefixes/components).
  4. Joins with destination and enforces containment by checking the cleaned final path starts with destination + / (or equals destination).

Then replace all pathBuilder(header.Name) calls with this validated path (computed once per header). For symlinks, also validate header.Linkname similarly before creating the symlink target path, so link targets cannot escape destination either.

Edits are confined to evetest/utils/tar.go: add one import (strings), add a safe-path helper closure in ExtractFromTar, compute validated entryPath per header, and use it in all file operations.

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

… during archive extraction ("Zip Slip")

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread evetest/utils/tar.go
safePath := func(oldPath string) (string, error) {
if oldPath == "" {
return "", fmt.Errorf("empty archive path")
}
Comment thread evetest/utils/tar.go
if err != nil {
return fmt.Errorf("ExtractFromTar: Next() failed: %w", err)
}
entryPath, err := safePath(header.Name)
Comment thread evetest/utils/tar.go
}
}
if err := os.Symlink(pathBuilder(header.Linkname), pathBuilder(header.Name)); err != nil {
linkPath, err := safePath(header.Linkname)
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.

2 participants