The unTar function constructs destination paths by concatenating the destination directory, a path separator, and the untrusted filename from the archive here:
dst := dstPath + "/" + header.Name
This is vulnerable to path traversal if header.Name contains ../outside for example.
The shortest code to sanitize the path would be:
header.Name = strings.TrimPrefix(filepath.Clean("/" + header.Name), "/")
Thank you.
The
unTarfunction constructs destination paths by concatenating the destination directory, a path separator, and the untrusted filename from the archive here:This is vulnerable to path traversal if
header.Namecontains../outsidefor example.The shortest code to sanitize the path would be:
Thank you.