Summary
A missing path validation flaw in openCode's Worktree.remove component allows a crafted payload to target directories outside the intended worktree. Successful exploitation may enable arbitrary recursive directory deletion, potentially causing severe data loss and service disruption.
Affected context
The vulnerability occurs in deployments using the Worktree.remove component of openCode v1.18.26 when attacker-controlled or insufficiently trusted path data reaches the deletion operation. Risk is increased when the component runs with access to sensitive directories or when supplied paths are not constrained to an approved worktree boundary.
Exploit preconditions
- Attack surface: The Worktree.remove path-handling interface
- Required access: Ability to submit or influence a payload processed by the component
- Trigger point: A recursive directory-removal operation
- Why exploitation is possible: The requested path is not adequately validated or confined to the intended directory before deletion
Why this happens
The underlying bug is insufficient canonicalization and boundary validation of a path used in a destructive filesystem operation. When user-controlled path components are accepted without verifying that the resolved target remains within an authorized worktree, an attacker may redirect the operation to unintended locations. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Potential impact
- An attacker may delete arbitrary directories recursively
- Application data and configuration files could be permanently lost
- Services may become unavailable because required files are removed
- Backups, credentials, or other sensitive local data could be affected
- Recovery and operational costs could increase substantially
General mitigation guidance
Mitigation generally focuses on treating deletion paths as untrusted and enforcing a strict filesystem boundary.
Common defensive patterns include:
- Canonicalizing paths before authorization and deletion
- Verifying that resolved targets remain within an approved worktree root
- Rejecting absolute paths, traversal components, links, and ambiguous path forms where appropriate
- Using an allowlist of removable directories rather than accepting arbitrary paths
- Separating validation from destructive execution and applying fail-closed behavior
- Running the component with the least filesystem privileges necessary
- Adding safeguards such as dry-run checks, deletion scopes, and recovery controls
How teams detect issues like this
Organizations can detect path traversal and unsafe deletion risks through:
- Static analysis for filesystem deletion calls that use externally influenced paths
- Code review checks for missing canonicalization, root-boundary validation, or symlink handling
- Tests covering absolute paths, traversal sequences, symbolic links, nested worktrees, and filesystem boundaries
- Runtime auditing of recursive deletion operations and unexpected target directories
- Policy enforcement requiring approved path helpers for destructive filesystem actions
Automated code review and security scanning tools may help identify untrusted path flow into deletion APIs.

