T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/delete_agent.py:128
- Finding
- Untrusted workspace configuration can cause recursive deletion of unrelated user data## Vulnerability Details **File Location**: `scripts/delete_agent.py`, lines 70-74 and 128-136 **Vulnerability Type**: Insufficient validation of a destructive filesystem target **Risk Level**: High ### Vulnerable Code ```python if target: removed["agent"] = True cfg["agents"]["list"] = new_agents removed["workspace"] = target.get("workspace") ``` ```python if args.delete_workspace and removed["workspace"]: wp = Path(removed["workspace"]).expanduser() # guardrail: only allow deleting workspaces under user's home and matching claw-* naming validate_within(Path.home(), wp, "workspace") if not wp.name.startswith("claw-"): raise SystemExit(f"Error: refusing unsafe workspace delete (expected claw-*): {wp}") if wp.exists(): shutil.rmtree(wp) ``` ### Technical Analysis The recursive deletion target is taken directly from the mutable `workspace` field in `~/.openclaw/openclaw.json`. The implemented checks only establish that the resolved path is beneath the current user's home directory and that its final component starts with `claw-`. These conditions do not prove that the directory belongs to the selected agent. Consequently, any unrelated directory beneath the user's home whose basename begins with `claw-` can satisfy the guardrails. If configuration integrity has been compromised or the workspace value was incorrectly assigned, `shutil.rmtree` recursively removes that unrelated directory. The path-resolution check does protect against straightforward traversal outside the home directory and against symlink targets resolving outside it. However, it does not provide ownership or agent-to-workspace binding validation. ### Attack Path 1. An attacker or another process with permission to modify `~/.openclaw/openclaw.json` changes the selected agent's `workspace` value to an unrelated directory such as `/home/user/projects/claw-important`. 2. The user follows the ...[truncated 826 chars]
- Remediation
- ## Remediation Suggestions - Do not authorize deletion based only on a name prefix. - Define a dedicated canonical workspace root and require all removable workspaces to be direct children of that root. - Derive the expected workspace path from the validated agent identifier where possible instead of trusting a mutable configuration path. - Store and verify an ownership marker inside the workspace, containing the corresponding agent ID. - Resolve the path before any destructive operation and reject symlinks, the home directory itself, filesystem roots, and paths that do not match the authoritative agent-to-workspace mapping. - Include the canonical target path in dry-run output and require path-specific confirmation for workspace deletion. - Consider moving the workspace into a recoverable quarantine or trash location before permanent removal. Example hardening logic should require all of the following: the canonical path is beneath the dedicated workspace root, its expected name exactly matches the selected agent, its ownership marker matches `agent_id`, and it is not a symbolic link.
