mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-24 02:48:02 +08:00
chore: stricter path checking when unpacking zip/tgz
This commit is contained in:
parent
ed42c4feb8
commit
a93479124c
@ -221,7 +221,7 @@ func unzip(src, dest string) (string, error) {
|
|||||||
fpath = filepath.Join(extractedFolder, f.Name)
|
fpath = filepath.Join(extractedFolder, f.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
|
if !inDest(fpath, dest) {
|
||||||
return "", fmt.Errorf("invalid file path: %s", fpath)
|
return "", fmt.Errorf("invalid file path: %s", fpath)
|
||||||
}
|
}
|
||||||
info := f.FileInfo()
|
info := f.FileInfo()
|
||||||
@ -344,7 +344,7 @@ func untgz(src, dest string) (string, error) {
|
|||||||
fpath = filepath.Join(extractedFolder, cleanTarPath(header.Name))
|
fpath = filepath.Join(extractedFolder, cleanTarPath(header.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
|
if !inDest(fpath, dest) {
|
||||||
return "", fmt.Errorf("invalid file path: %s", fpath)
|
return "", fmt.Errorf("invalid file path: %s", fpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,3 +421,12 @@ func cleanup(root string) error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inDest(fpath, dest string) bool {
|
||||||
|
if rel, err := filepath.Rel(dest, fpath); err == nil {
|
||||||
|
if filepath.IsLocal(rel) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user