mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-23 18:38:09 +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)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
|
||||
if !inDest(fpath, dest) {
|
||||
return "", fmt.Errorf("invalid file path: %s", fpath)
|
||||
}
|
||||
info := f.FileInfo()
|
||||
@ -344,7 +344,7 @@ func untgz(src, dest string) (string, error) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -421,3 +421,12 @@ func cleanup(root string) error {
|
||||
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