"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
cmd/rcd: Address ZipSlip vulnerability
Richard Patel32d5af8fb61a
diff --git a/cmd/rcd/rcd.go b/cmd/rcd/rcd.goindex d6f360b96..0e2b15fde 100644--- a/cmd/rcd/rcd.go+++ b/cmd/rcd/rcd.go@@ -3,12 +3,14 @@ package rcdimport ("archive/zip""encoding/json"+ "fmt""io""log""net/http""os""path/filepath""strconv"+ "strings""time""github.com/rclone/rclone/cmd"@@ -179,6 +181,8 @@ func downloadFile(filepath string, url string) error {// unzip is a helper function to unzip a file specified in src to path destfunc unzip(src, dest string) (err error) {+ dest = filepath.Clean(dest) + string(os.PathSeparator)+r, err := zip.OpenReader(src)if err != nil {return err@@ -191,14 +195,18 @@ func unzip(src, dest string) (err error) {// Closure to address file descriptors issue with all the deferred .Close() methodsextractAndWriteFile := func(f *zip.File) error {+ path := filepath.Join(dest, f.Name)+ // Check for Zip Slip: https://github.com/rclone/rclone/issues/3529+ if !strings.HasPrefix(path, dest) {+ return fmt.Errorf("%s: illegal file path", path)+ }+rc, err := f.Open()if err != nil {return err}defer fs.CheckClose(rc, &err)- path := filepath.Join(dest, f.Name)-if f.FileInfo().IsDir() {if err := os.MkdirAll(path, 0755); err != nil {return err