"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
archive: reject unsafe entry names when mounting squashfs images GHSA-66hp-wgxq-6f5q
Nick Craig-Wood7a00e13cd04a
diff --git a/backend/archive/squashfs/squashfs.go b/backend/archive/squashfs/squashfs.goindex 86cfd72ee..47868010e 100644--- a/backend/archive/squashfs/squashfs.go+++ b/backend/archive/squashfs/squashfs.go@@ -16,6 +16,7 @@ import ("github.com/rclone/rclone/fs/hash""github.com/rclone/rclone/fs/log""github.com/rclone/rclone/lib/readers"+ "github.com/rclone/rclone/lib/sanitize""github.com/rclone/rclone/vfs""github.com/rclone/rclone/vfs/vfscommon")@@ -237,8 +238,15 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e}entries = make(fs.DirEntries, 0, len(items))+ skipped := 0for _, item := range items {// fs.Debugf(item.Name(), "entry = %#v", item)+ // Skip entry names that aren't safe+ if err := sanitize.Leaf(item.Name()); err != nil {+ fs.Debugf(f, "Skipping squashfs entry %q which escapes the archive", item.Name())+ skipped+++ continue+ }var entry fs.DirEntryif item.IsDir() {remote := f.fromNative(nativeDir, item.Name())@@ -260,6 +268,12 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err eentries = append(entries, entry)}+ // Log once per listing rather than per entry so a crafted image+ // can't flood the log+ if skipped > 0 {+ fs.Logf(f, "Skipped %d squashfs entries in %q whose names escape the archive", skipped, dir)+ }+// fs.Debugf(f, "dir=%q, entries=%v", dir, entries)return entries, nil}diff --git a/backend/archive/squashfs/squashfs_internal_test.go b/backend/archive/squashfs/squashfs_internal_test.gonew file mode 100644index 000000000..9b071bf0e--- /dev/null+++ b/backend/archive/squashfs/squashfs_internal_test.go@@ -0,0 +1,32 @@+package squashfs++import (+ "context"+ "testing"++ _ "github.com/rclone/rclone/backend/local"+ fscache "github.com/rclone/rclone/fs/cache"+ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++// A backslash is an ordinary character in a file name on the systems+// squashfs images are made on, so an entry containing one must be+// listed and openable like any other file.+func TestBackslashInName(t *testing.T) {+ ctx := context.Background()+ localFs, err := fscache.Get(ctx, "testdata")+ require.NoError(t, err)++ f, err := New(ctx, localFs, "backslash.sqfs", "", "")+ require.NoError(t, err)++ entries, err := f.List(ctx, "")+ require.NoError(t, err)+ require.Len(t, entries, 1)+ assert.Equal(t, `back\slash.txt`, entries[0].Remote())++ o, err := f.NewObject(ctx, `back\slash.txt`)+ require.NoError(t, err)+ assert.Equal(t, int64(6), o.Size())+}diff --git a/backend/archive/squashfs/testdata/backslash.sqfs b/backend/archive/squashfs/testdata/backslash.sqfsnew file mode 100644index 000000000..81efc35deBinary files /dev/null and b/backend/archive/squashfs/testdata/backslash.sqfs differ