Skip to content

Commit

Permalink
Potential fix for code scanning alert no. 57: Arbitrary file access d…
Browse files Browse the repository at this point in the history
…uring archive extraction ("Zip Slip") (#4604)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
kevwan and github-advanced-security[bot] authored Jan 27, 2025
1 parent a32f6d7 commit c71829c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/goctl/util/zipx/zipx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package zipx

import (
"archive/zip"
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
)
Expand Down Expand Up @@ -39,6 +41,12 @@ func fileCopy(file *zip.File, destPath string) error {
return err
}
defer rc.Close()

// Ensure the file path does not contain directory traversal elements
if strings.Contains(file.Name, "..") {
return fmt.Errorf("invalid file path: %s", file.Name)
}

abs, err := filepath.Abs(file.Name)
if err != nil {
return err
Expand Down

0 comments on commit c71829c

Please sign in to comment.