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.

