"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
serve s3: fix presigned URL being turned into a copy of any object GHSA-w3h7-jxxq-vfrp CVE-PENDING
Nick Craig-Woodc3b582ccdf53
diff --git a/cmd/serve/s3/s3_test.go b/cmd/serve/s3/s3_test.goindex a1fb6f63d..37d4d399c 100644--- a/cmd/serve/s3/s3_test.go+++ b/cmd/serve/s3/s3_test.go@@ -34,6 +34,7 @@ import ("github.com/rclone/rclone/fs/object""github.com/rclone/rclone/fs/rc""github.com/rclone/rclone/fstest"+ "github.com/rclone/rclone/fstest/fstests""github.com/rclone/rclone/fstest/testy""github.com/rclone/rclone/lib/random""github.com/rclone/rclone/vfs"@@ -704,6 +705,112 @@ func TestListObjectsDelimitedPagingWithMinioClient(t *testing.T) {}}+// testUnsignedAmzHeader checks that a request carrying an x-amz-*+// header which is not in its signed headers list is refused, as AWS+// does. Otherwise a presigned PUT URL for one object, which signs only+// the host header, could be turned into a copy from any object the+// server can reach by adding an unsigned x-amz-copy-source header.+func testUnsignedAmzHeader(t *testing.T, useProxy bool) {+ fstest.Initialise()+ root := t.TempDir()+ f, err := fs.NewFs(context.Background(), root)+ require.NoError(t, err)++ const (+ secret = "THIS-IS-THE-VICTIM-FILE"+ original = "PLACEHOLDER-ORIGINAL-CONTENT"+ uploaded = "UPLOADED-WITH-PRESIGNED-URL"+ )+ ctx := context.Background()+ fstests.PutTestContents(ctx, t, f, &fstest.Item{Path: "src/secret.txt", ModTime: time.Now()}, secret, true)+ fstests.PutTestContents(ctx, t, f, &fstest.Item{Path: "dst/target.txt", ModTime: time.Now()}, original, true)+ readFile := func(name string) string {+ return fstests.ReadObject(ctx, t, fstest.NewObject(ctx, t, f, name), -1)+ }++ serveFs := f+ if useProxy {+ prog, err := filepath.Abs("../servetest/proxy_code.go")+ require.NoError(t, err)+ proxy.Opt.AuthProxy = "go run " + prog + " " + root+ defer func() {+ proxy.Opt.AuthProxy = ""+ }()+ serveFs = nil+ }+ endpoint, keyid, keysec, s := serveS3(t, serveFs)+ defer func() {+ assert.NoError(t, s.server.Shutdown())+ }()++ creds := aws.Credentials{AccessKeyID: keyid, SecretAccessKey: keysec}+ do := func(req *http.Request) (int, string) {+ resp, err := http.DefaultClient.Do(req)+ require.NoError(t, err)+ body, _ := io.ReadAll(resp.Body)+ _ = resp.Body.Close()+ return resp.StatusCode, string(body)+ }+ sign := func(req *http.Request) {+ req.Header.Set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD")+ err := v4.NewSigner().SignHTTP(context.Background(), creds, req, "UNSIGNED-PAYLOAD", "s3", "us-east-1", time.Now())+ require.NoError(t, err)+ }++ // A presigned PUT URL for dst/target.txt which signs only the host header+ req, err := http.NewRequest("PUT", endpoint+"/dst/target.txt", nil)+ require.NoError(t, err)+ presigned, _, err := v4.NewSigner().PresignHTTP(context.Background(), creds, req, "UNSIGNED-PAYLOAD", "s3", "us-east-1", time.Now())+ require.NoError(t, err)+ presignedURL, err := url.Parse(presigned)+ require.NoError(t, err)+ require.Equal(t, "host", presignedURL.Query().Get("X-Amz-SignedHeaders"))++ // It works as intended+ req, err = http.NewRequest("PUT", presigned, strings.NewReader(uploaded))+ require.NoError(t, err)+ status, body := do(req)+ assert.Equal(t, http.StatusOK, status, body)+ assert.Equal(t, uploaded, readFile("dst/target.txt"))++ // But must not become a copy from an object the URL does not name+ req, err = http.NewRequest("PUT", presigned, nil)+ require.NoError(t, err)+ req.Header.Set("x-amz-copy-source", "/src/secret.txt")+ status, body = do(req)+ assert.Equal(t, http.StatusForbidden, status, body)+ assert.Contains(t, body, "AccessDenied")+ assert.Equal(t, uploaded, readFile("dst/target.txt"))++ // Nor may an unsigned header be added to a request signed with an+ // Authorization header+ req, err = http.NewRequest("PUT", endpoint+"/dst/target.txt", nil)+ require.NoError(t, err)+ sign(req)+ req.Header.Set("x-amz-copy-source", "/src/secret.txt")+ status, body = do(req)+ assert.Equal(t, http.StatusForbidden, status, body)+ assert.Contains(t, body, "AccessDenied")+ assert.Equal(t, uploaded, readFile("dst/target.txt"))++ // Whereas a copy whose x-amz-copy-source header is signed is allowed+ req, err = http.NewRequest("PUT", endpoint+"/dst/target.txt", nil)+ require.NoError(t, err)+ req.Header.Set("x-amz-copy-source", "/src/secret.txt")+ sign(req)+ status, body = do(req)+ assert.Equal(t, http.StatusOK, status, body)+ assert.Equal(t, secret, readFile("dst/target.txt"))+}++func TestUnsignedAmzHeader(t *testing.T) {+ testUnsignedAmzHeader(t, false)+}++func TestUnsignedAmzHeaderAuthProxy(t *testing.T) {+ testUnsignedAmzHeader(t, true)+}+func TestRc(t *testing.T) {servetest.TestRc(t, rc.Params{"type": "s3",diff --git a/cmd/serve/s3/serve_s3.md b/cmd/serve/s3/serve_s3.mdindex c31b0645b..c659cfeb7 100644--- a/cmd/serve/s3/serve_s3.md+++ b/cmd/serve/s3/serve_s3.md@@ -21,6 +21,13 @@ returns for its access key ID. Each access key ID is a separate user,whose multipart uploads and object metadata are private to it, even ifthe proxy maps several access key IDs to the same backend.+As on AWS, every `x-amz-*` header in an authenticated request must be+in its signed headers list; a request with an unsigned `x-amz-*`+header is refused with `AccessDenied`. S3 clients sign these headers+as a matter of course, but a header added after signing (for example+by a proxy in front of the server, or `x-amz-meta-*` headers sent+with a presigned URL which only signs the host) is refused.+Like all rclone flags `--auth-key` can be set via environmentvariables, in this case `RCLONE_AUTH_KEY`. Since this flag can berepeated, the input to `RCLONE_AUTH_KEY` is CSV encoded. Because thediff --git a/go.mod b/go.modindex 16954bd9a..fa6a9cc8b 100644--- a/go.mod+++ b/go.mod@@ -75,7 +75,7 @@ require (github.com/quasilyte/go-ruleguard/dsl v0.3.23github.com/rclone/Proton-API-Bridge v1.0.5github.com/rclone/go-proton-api v1.0.4- github.com/rclone/gofakes3 v0.0.10-0.20260923152001-4a6b9490d9c0+ github.com/rclone/gofakes3 v0.0.10github.com/rfjakob/eme v1.2.0github.com/rivo/uniseg v0.4.7github.com/rogpeppe/go-internal v1.15.0diff --git a/go.sum b/go.sumindex ca77054f6..719592636 100644--- a/go.sum+++ b/go.sum@@ -494,10 +494,8 @@ github.com/rclone/Proton-API-Bridge v1.0.5 h1:K1++Qtk3PvgkiCCiv6Pahju1TMOzKY6VSwgithub.com/rclone/Proton-API-Bridge v1.0.5/go.mod h1:vCeOPhlXzevN0AFojgh1zsjhetiShy/ArvJ/xkFUDWk=github.com/rclone/go-proton-api v1.0.4 h1:AJW0e9pB4j0hVK4WqyGErFwaI+5MUQWPCtj5FYYxtPg=github.com/rclone/go-proton-api v1.0.4/go.mod h1:QAlkFfswzrBuxvCORWV8rZdddg52hahMN98CFWoFW1E=-github.com/rclone/gofakes3 v0.0.10-0.20260919171726-8edbb055e5ec h1:6JAnhUd7+U6wWrS14qpWnhNXWD/xtxNd8qVwyNvjflw=-github.com/rclone/gofakes3 v0.0.10-0.20260919171726-8edbb055e5ec/go.mod h1:0udb2hmIO9mHXDAgcdycCzSPPASAGIz410t+m0LKmnE=-github.com/rclone/gofakes3 v0.0.10-0.20260923152001-4a6b9490d9c0 h1:RrKcq7t/Ta43Ua9ABr+0SbLlsYH84XyExA6rVSVrqY8=-github.com/rclone/gofakes3 v0.0.10-0.20260923152001-4a6b9490d9c0/go.mod h1:0udb2hmIO9mHXDAgcdycCzSPPASAGIz410t+m0LKmnE=+github.com/rclone/gofakes3 v0.0.10 h1:LIwNoz4PzpldElhyC7+SI4WwZmytlwoFky6AzTTe5B8=+github.com/rclone/gofakes3 v0.0.10/go.mod h1:0udb2hmIO9mHXDAgcdycCzSPPASAGIz410t+m0LKmnE=github.com/relvacode/iso8601 v1.7.0 h1:BXy+V60stMP6cpswc+a93Mq3e65PfXCgDFfhvNNGrdo=github.com/relvacode/iso8601 v1.7.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=github.com/rfjakob/eme v1.2.0 h1:8dAHL+WVAw06+7DkRKnRiFp1JL3QjcJEZFqDnndUaSI=