GHSA-7p4m-qxvv-g567 rclone: Local Encoding Path Traversal
SummaryThe 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 SurfaceConfirmed 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 configurationThe destination is a local backend whose effective encoding does not safely encode `.` and `..` components. Examples include: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 inputThe 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: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 operationsThe 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 AnalysisRclone 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:When a standard path is converted for a destination backend, `lib/encoder/encoder.go:1214-1240` performs the following transformation for every path component:For a destination encoding that omits `Dot`:`Standard.Decode("．．")` returns `".."`.The destination encoder leaves `".."` unchanged.`FromStandardPath` returns a path containing an actual parent-directory component.The local backend then constructs the native path without validating containment:`filepath.Join` cleans the resulting path. For example:`Put` creates an object from `src.Remote()`, and `Object.Update` eventually opens that resolved path using: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 & EvidenceDeterministic regression testAdd 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.Run:Observed result against commit `a0c09f1381ae93e2a9a33c529d170186c61ad058`: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 variantA second regression test was run on Windows using the standard remote name:and a local destination configured with: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 reproductionPerform this test only with a disposable bucket and temporary local paths.Expected result:is created outside: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 AssessmentThe 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 GuidanceEnforce containment after native-path conversionThe 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:Convert the standard remote name using the configured local encoding.Convert separators to the native format.Reject any non-empty result for which `filepath.IsLocal` is false. This rejects absolute, volume-qualified, and lexically escaping paths using platform-aware rules.Join the result to `f.root`.Calculate `filepath.Rel(f.root, candidate)` using the normalized `f.root`, not the original user-supplied root string.Reject `rel == ".."`, any relative path beginning with `".." + filepath.Separator`, and any absolute relative result.Illustrative logic: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 pointThe 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 operationsThe 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.
CVSS v3.1 score: 6.9