Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading