File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -945,11 +945,18 @@ func untar(tarPath string, destPath string) error {
945945 continue
946946 }
947947 target := filepath .Join (dest , filepath .Clean (header .Name ))
948+ if ! strings .HasPrefix (target , filepath .Clean (dest )+ string (os .PathSeparator )) {
949+ return fmt .Errorf ("illegal file path: %s" , header .Name )
950+ }
948951 if err := os .MkdirAll (filepath .Dir (target ), 0o755 ); err != nil && os .IsExist (err ) {
949952 return err
950953 }
951954 switch header .Typeflag {
952955 case tar .TypeSymlink :
956+ linkTarget := filepath .Join (filepath .Dir (target ), header .Linkname )
957+ if ! strings .HasPrefix (filepath .Clean (linkTarget ), filepath .Clean (dest )+ string (os .PathSeparator )) {
958+ return fmt .Errorf ("illegal symlink target: %s -> %s" , header .Name , header .Linkname )
959+ }
953960 err := os .Symlink (header .Linkname , target )
954961 if err != nil {
955962 return err
You can’t perform that action at this time.
0 commit comments