/

CVE-2026-41589

Severity:

CRITICAL RISK

(9.6)

Path Traversal in Wish SCP Middleware Allows Arbitrary File

CVE-2026-41589

Analyzed

Vulnerability type

Category:

Path Traversal / Directory Traversal

CWE:

CWE-22

Impact:

Arbitrary File Read and Write on Server Filesystem

Severity:

CRITICAL RISK

(9.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A path traversal vulnerability in the SCP middleware of the Wish SSH server (charm.land/wish/v2) allows crafted filenames containing ../ sequences to escape the configured root directory.

Under affected versions, a malicious SCP client may read or write arbitrary files and create directories on the server filesystem outside the intended SCP root.

Affected context

This vulnerability appears in deployments using the Wish SSH server with the SCP middleware from version 2.0.0 up to (but not including) 2.0.1.

It manifests when the server exposes SCP functionality and relies on a configured root directory or chroot-like path for isolating file operations.

The issue arises specifically in the path normalization and validation logic that processes SCP filenames sent by clients, allowing traversal above the configured root if not carefully constrained.

Exploit preconditions

  • Attack surface: SCP service exposed via Wish SSH server using the vulnerable SCP middleware.
  • Required access: Ability to authenticate or otherwise establish an SCP session to the server (according to how the service is configured); no shell access is required, only SCP capability.
  • Trigger point: Uploading or requesting files via SCP using specially crafted filenames containing directory traversal sequences such as ../.
  • Why exploitation is possible: The SCP middleware does not correctly canonicalize and validate client-supplied paths relative to the configured root, allowing traversal outside the intended directory sandbox.

Why this happens

The underlying bug is improper restriction of file system paths based on user-controlled input, a classic CWE-22: Path Traversal issue.

The SCP middleware accepts filenames from the client and combines them with a server-side root directory, but fails to robustly normalize and validate the resulting path.

Insecure patterns typically include:

  • Simple string concatenation of root + user path without canonicalization.
  • Checking for prefixes or prohibiting certain substrings in a way that does not consider symbolic links or encoded traversal patterns.
  • Performing validation on a non-canonical path, then using a different or transformed path for the actual filesystem operation.

Because the SCP protocol allows arbitrary filenames, the lack of strict path resolution and enforcement enables an attacker to use sequences like ../ to escape the configured root.

Potential impact

  • Read access to arbitrary files on the server that are readable by the Wish SCP process (e.g., configuration files, application data).
  • Write access to arbitrary files, potentially overwriting existing data or planting malicious files (e.g., web shells, cron jobs, or configuration changes).
  • Creation of directories outside the intended SCP root, which can be used to prepare for further attacks or persistence mechanisms.
  • Indirect escalation of impact if sensitive files (such as keys, credentials, or application configs) are exposed or modified.
  • Potential compromise of other services that consume or execute data from the affected filesystem paths.

General mitigation guidance

Effective mitigation focuses on enforcing strict, canonical path handling and minimizing the privileges of the SCP middleware:

  • Normalize and canonicalize all client-supplied paths against a configured root, then verify that the resolved absolute path remains strictly within that root before performing any filesystem operation.
  • Use robust filesystem APIs that operate on canonical paths rather than manual string concatenation or prefix checks.
  • Treat all SCP filenames as untrusted input and explicitly reject paths containing traversal semantics (../, absolute paths, or drive specifiers on relevant platforms).
  • Employ a true chroot jail, container, or similar isolation boundary for the SCP service to limit blast radius if path validation fails.
  • Run the SCP middleware under a dedicated, least-privileged account with only the minimal file permissions required for legitimate operations.
  • Consider read-only mounts where appropriate to reduce the risk of unauthorized file creation or modification.

These patterns reduce reliance on ad hoc path checks and increase resilience against variations of traversal payloads.

How teams detect issues like this

Detection can combine code-centric analysis and operational monitoring:

  • Static analysis: Configure rules or custom checks to flag any file operations that combine a configured root path with user-controlled input without canonicalization and strict boundary checks.
  • Code review cues: Pay attention to path handling in SCP or file transfer components, looking for:
  • Direct concatenation of root + user paths.
  • Ad hoc string checks like if strings.Contains(path, "..") instead of using canonical path APIs.
  • Lack of a final invariant check that the target path starts with the canonical root path.
  • Automated tooling: Integrate security linters and SAST tools into CI pipelines to identify CWE-22 patterns around filesystem access functions.
  • Runtime monitoring: Use logs and file integrity monitoring to detect unusual file access patterns, such as SCP actions accessing directories outside the expected root or touching sensitive system files.

Combining pre-deployment analysis with runtime visibility helps catch both this specific flaw and future regressions in path handling logic.

Sources

SourceLink
github.comgithub.com/charmbracelet/wish/releases/tag/v2.0.1
github.comgithub.com/charmbracelet/wish/security/advisories/GHSA-xjvp-7243-rg9h

Frequently asked

questions

Yes. Any attacker who can establish an SCP session to the vulnerable Wish server can attempt to exploit the traversal issue by crafting malicious filenames, subject to authentication and network access controls.

The attacker needs the ability to connect to the Wish SSH server and use SCP. In many deployments, this requires valid SSH credentials or keys, but if SCP is exposed to untrusted users or misconfigured, the practical barrier can be low.

The safest pattern is to enforce canonical, root-relative path resolution for all SCP operations. Resolve the requested path to an absolute canonical path, verify it remains within the configured root directory, and only then perform the filesystem operation. Combining this with a hardened runtime environment (such as a chroot or container) further reduces risk.

Treat all file paths derived from external input as untrusted, enforce strict path normalization and boundary checks, and make least-privilege and isolation default for file-handling components. Incorporating security-focused code review, automated static analysis for CWE-22, and documented path-handling patterns into development practices helps prevent recurrence across file transfer and storage features.

Find out what's already
exploitable in your codebase.