Advisory

GHSA-7p4m-qxvv-g567

Details, part 2 of 2. The advisory

Details

Run:

go test ./backend/local -run '^TestLocalEncodingWithoutDotEscapesRoot$' -count=1 -v

Observed result against commit a0c09f1381ae93e2a9a33c529d170186c61ad058:

=== 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:

..\backslash-marker.txt

and a local destination configured with:

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.

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:

/tmp/rclone-traversal-marker.txt

is created outside:

/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:

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.

Sources & licences