"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
local: limit the size of symlink targets read from .rclonelink files
Nick Craig-Wood0be5c88394f4
diff --git a/backend/local/local.go b/backend/local/local.goindex e76ef3823..7db5e2c4c 100644--- a/backend/local/local.go+++ b/backend/local/local.go@@ -37,6 +37,10 @@ import (const (devUnset = 0xdeadbeefcafebabe // a device id meaning it is unsetuseReadDir = (runtime.GOOS == "windows" || runtime.GOOS == "plan9") // these OSes read FileInfos directly+ // maxLinkTargetSize is the largest symlink target accepted when+ // translating a .rclonelink object, comfortably above any OS path+ // limit (Windows allows 32767 UTF-16 units).+ maxLinkTargetSize = 128 * 1024)// timeType allows the user to choose what exactly ModTime() returns@@ -440,6 +444,7 @@ var (errLinksNeedsSuffix = errors.New("need \"" + fs.LinkSuffix + "\" suffix to refer to symlink when using -l/--links")errPathEscapes = errors.New("file name is not a path within the local root - check the encoding")errSymlinkLoop = errors.New("loop detected: points to a parent directory")+ errLinkTargetTooLong = errors.New("symlink target is too long to be a path"))// NewFs constructs an Fs from the path@@ -1736,6 +1741,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op}out = f} else {+ // The target is buffered in memory, so stop reading just past+ // the longest acceptable one rather than trust the source+ in = io.LimitReader(in, maxLinkTargetSize+1)out = nopWriterCloser{&symlinkData}}@@ -1752,6 +1760,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op}if o.translatedLink {+ if err == nil && symlinkData.Len() > maxLinkTargetSize {+ err = fserrors.NoRetryError(errLinkTargetTooLong)+ }if err == nil {// Use the contents of the copied object to create a symlink,// without following or creating it through a planted symlinkdiff --git a/backend/local/local_internal_test.go b/backend/local/local_internal_test.goindex 3a972c15e..ab5a2f6db 100644--- a/backend/local/local_internal_test.go+++ b/backend/local/local_internal_test.go@@ -272,6 +272,29 @@ func linksMode(f *Fs) {f.lstat = os.Lstat}+// TestSymlinkTargetTooLong checks that a .rclonelink object whose body is+// far bigger than any path is refused without being buffered in memory,+// and that nothing is created at the destination.+func TestSymlinkTargetTooLong(t *testing.T) {+ skipIfNoSymlinks(t)+ ctx := context.Background()++ r := fstest.NewRun(t)+ f := r.Flocal.(*Fs)+ linksMode(f)++ // A source which never ends, so the read must be bounded+ src := object.NewStaticObjectInfo("big"+fs.LinkSuffix, fstest.Time("2001-02-03T04:05:10Z"), -1, true, nil, nil)+ in := readers.NewCountingReader(readers.NewPatternReader(1 << 40))+ _, err := f.Put(ctx, in, src)+ require.ErrorIs(t, err, errLinkTargetTooLong)+ assert.True(t, fserrors.IsNoRetryError(err))+ assert.LessOrEqual(t, in.BytesRead(), uint64(maxLinkTargetSize+1), "read more of the body than needed")++ _, err = os.Lstat(filepath.Join(f.root, "big"))+ assert.True(t, os.IsNotExist(err), "nothing should be created for a refused symlink")+}+// TestSymlinkEscapeWriteThroughBlocked mirrors the GHSA-cf44-9pgv-m4xc PoC: a// malicious --links source serves "pwn.rclonelink" whose body is a path outside// the destination, plus a sibling "pwn/authkeys" that sorts after it and woulddiff --git a/docs/content/local.md b/docs/content/local.mdindex 178fb97e4..433a48774 100644--- a/docs/content/local.md+++ b/docs/content/local.md@@ -272,6 +272,9 @@ $ tree /tmp/b└── file2 -> /home/user/file3```+A `.rclonelink` file whose contents are too long to be a path (more+than 128 KiB) is refused rather than turned into a symlink.+However, if copied back without '-l'```console