Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

http: stop a path starting with // moving the remote to another host GHSA-xqmq-v4wj-rw5m CVE-PENDING

Nick Craig-Woodecd821243f71
diff --git a/backend/http/http.go b/backend/http/http.go
index b18657009..b254a5021 100644
--- a/backend/http/http.go
+++ b/backend/http/http.go
@@ -283,7 +283,7 @@ func (f *Fs) httpConnection(ctx context.Context, opt *Options) (isFile bool, err
if err != nil {
return false, err
}
- u, err := rest.URLJoin(base, rest.URLPathEscape(f.root))
+ u, err := rest.URLJoinRoot(base, f.root)
if err != nil {
return false, err
}
diff --git a/backend/http/http_internal_test.go b/backend/http/http_internal_test.go
index 01e637cc5..fd48c7173 100644
--- a/backend/http/http_internal_test.go
+++ b/backend/http/http_internal_test.go
@@ -760,3 +760,34 @@ func TestRedirectStripsHeadersOnHostChange(t *testing.T) {
assert.Empty(t, got.Values(headers[i]), "header %q leaked to redirect target", headers[i])
}
}
+
+func TestRootCannotChangeHost(t *testing.T) {
+ // A root starting with "//" is a network-path reference under the
+ // URL standard. It must not be able to move the remote (and the
+ // configured headers) to a host other than the configured one.
+ var requests int
+ other := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ requests++
+ _, _ = w.Write([]byte("hello"))
+ }))
+ defer other.Close()
+
+ m := prepareServer(t)
+ otherHost := strings.TrimPrefix(other.URL, "http://")
+ for _, root := range []string{
+ "//" + otherHost + "/",
+ "//" + otherHost + "/one%.txt",
+ "//" + otherHost,
+ "//user:pass@" + otherHost + "/",
+ } {
+ f, err := NewFs(context.Background(), remoteName, root, m)
+ assert.ErrorContains(t, err, "must not change the scheme, host or user", root)
+ assert.Nil(t, f, root)
+ }
+ assert.Equal(t, 0, requests, "request sent to the other host")
+
+ // A same-origin absolute path must still work
+ f, err := NewFs(context.Background(), remoteName, "/", m)
+ require.NoError(t, err)
+ assert.Equal(t, m["url"]+"/", f.String())
+}
diff --git a/docs/content/http.md b/docs/content/http.md
index 98fe9051d..c3c8beccd 100644
--- a/docs/content/http.md
+++ b/docs/content/http.md
@@ -20,7 +20,9 @@ it will be resolved relative to this url, according to the URL standard. This
means with remote url `https://beta.rclone.org/branch` and path `fix`, the
resolved URL will be `https://beta.rclone.org/branch/fix`, while with path
`/fix` the resolved URL will be `https://beta.rclone.org/fix` as the absolute
-path is resolved from the root of the domain.
+path is resolved from the root of the domain. The path can't change the scheme,
+host or user of the configured url, so a path such as `//other.example.com/fix`
+is rejected.
If the path following the `remote:` ends with `/` it will be assumed to point
to a directory. If the path does not end with `/`, then a HEAD request is sent