Skip to content

Commit d7b94fe

Browse files
committed
fix zipslip
1 parent 965e4f0 commit d7b94fe

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fsutil/operate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package fsutil
22

33
import (
44
"archive/zip"
5+
"fmt"
56
"io"
67
"io/ioutil"
78
"os"
89
"path"
910
"path/filepath"
11+
"strings"
1012
)
1113

1214
// Mkdir alias of os.MkdirAll()
@@ -317,7 +319,13 @@ func Unzip(archive, targetDir string) (err error) {
317319
}
318320

319321
for _, file := range reader.File {
322+
323+
if strings.Contains(file.Name, "..") {
324+
return fmt.Errorf("illegal file path in zip: %v", file.Name)
325+
}
326+
320327
fullPath := filepath.Join(targetDir, file.Name)
328+
321329
if file.FileInfo().IsDir() {
322330
err = os.MkdirAll(fullPath, file.Mode())
323331
if err != nil {

0 commit comments

Comments
 (0)