Summary
Magic Wormhole versions 0.21.0 to before 0.23.0 contain a path traversal vulnerability in the wormhole receive operation that can allow a malicious sender to overwrite critical files on the receiver's system.
By crafting file paths that target locations like ~/.ssh/authorized_keys or .bashrc, an attacker who controls the sending side may be able to compromise the receiver's machine when they accept the transfer.
Affected context
The vulnerability occurs in Magic Wormhole's file receiving logic when a user runs wormhole receive and accepts content from a peer.
It is relevant in scenarios where the receiver implicitly trusts the sender or does not inspect the file paths being transferred.
The risk materializes when the application allows received files or directories to be written without sufficient validation of their destination paths, enabling writes outside the intended download directory and into sensitive locations in the user's home directory.
Exploit preconditions
- Attack surface: The
wormhole receivecommand on a user's machine. - Required access: The attacker must be the sender in an established Magic Wormhole session; they need the ability to initiate
wormhole sendand get the receiver to complete the transfer. - User interaction: The receiver must accept the transfer, typically trusting the sender or the code phrase/connection setup.
- Trigger point: The vulnerability is triggered when the receiving side writes the incoming file or directory structure to disk using attacker-controlled path information.
- Why exploitation is possible: The file handling logic fails to adequately sanitize or constrain incoming paths, allowing traversal out of the intended receive directory and enabling overwrites of existing files in sensitive locations.
Why this happens
This vulnerability stems from inadequate validation of file and directory paths supplied by the remote sender before writing them to the local filesystem.
When the receiving code trusts inbound metadata (such as filenames or relative paths) and combines them with the local filesystem without enforcing strict constraints, an attacker can craft paths that escape the intended destination directory.
This is a typical CWE-22: Path Traversal pattern, where untrusted input is used in file system operations (creation or overwrite) without normalization and boundary checks, permitting writes to arbitrary locations under the user's permissions.
Potential impact
- Overwrite of critical shell configuration files (e.g.,
.bashrc) which could be used to execute attacker-controlled commands when the shell starts. - Overwrite of SSH authorization files (e.g.,
~/.ssh/authorized_keys), allowing the attacker to gain persistent remote access using their own SSH key. - Modification or corruption of other application or configuration files in the user's home directory.
- Loss of integrity and potential loss of availability for user data stored in overwritten files.
- Broader system compromise if overwritten files are used in privileged or security-sensitive workflows.
General mitigation guidance
Mitigation focuses on constraining where received files can be written and eliminating the influence of untrusted path components on filesystem operations.
Useful defensive patterns include:
- Normalizing and validating filenames and directory paths before writing them, rejecting or sanitizing any input that attempts to traverse outside the intended receive directory.
- Enforcing a dedicated, application-controlled download directory and preventing writes above this root (e.g., via path canonicalization and prefix checks).
- Stripping or rejecting path separators, parent directory references (
..), absolute paths, or leading home-directory indicators from filenames provided by the sender. - Applying a "safe list" approach for allowed path patterns and explicitly blocking unusual or control-character-laden names.
- Running the application with least-privilege filesystem permissions, avoiding execution in contexts where overwriting configuration files would have severe consequences.
How teams detect issues like this
Organizations can detect similar issues through a combination of code-centric and behavior-centric approaches:
- Static analysis: Configure rules to flag uses of attacker-controlled or network-derived path components that feed into file
open,write, or extraction operations without normalization and boundary checks. - Code review: Look for file handling logic in receive or sync features where filenames originate from peers, archives, or external metadata; verify that paths are canonicalized and constrained to a safe root directory.
- Security testing: Perform dynamic tests where crafted filenames (including
../, absolute paths, home-directory references, and nested directory structures) are sent to the receiver to observe whether files are created outside the expected directory. - Policy enforcement: Integrate automated checks in CI pipelines that scan for dangerous file handling patterns and require security review for any feature that writes files based on remote input.

