T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/safe_clone.sh:129
- Finding
- Arbitrary Recursive Deletion Through an Unrestricted Target Directory<![CDATA[ ## Vulnerability Details **File Location**: `scripts/safe_clone.sh`, lines 129–140 **Vulnerability Type**: Unrestricted recursive deletion of a user-controlled path **Risk Level**: High ### Vulnerable Code ```bash # Check whether the target directory exists if [[ -d "$target_dir" ]]; then log_warning "Target directory already exists: $target_dir" read -p "Overwrite? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then log_error "Operation cancelled" return 1 fi rm -rf "$target_dir" fi # Perform the clone if git clone --depth "$depth" "$url" "$target_dir" 2>/dev/null; then ``` The comments and messages above are translated into English for reporting; the executable statements are unchanged. ### Technical Analysis The script accepts `target_dir` as a command-line argument and passes it directly to: ```bash rm -rf "$target_dir" ``` Quoting prevents shell word splitting and command substitution, but it does not make the selected path safe. The script does not: - Resolve the path to its canonical location. - Reject `/`, the user's home directory, or another sensitive location. - Reject parent-directory traversal components such as `..`. - Restrict clones to a dedicated destination root. - Verify that the directory was previously created by this tool. - Reject a symbolic-link-based destination. - Verify that the directory is empty or contains only expected clone data. The interactive confirmation reduces accidental exploitation but is not an adequate authorization boundary. A user can misunderstand the prompt, and an automated agent, wrapper, or scripted input can approve it. ### Attack Path 1. An attacker influences the target directory supplied to the skill, or a user accidentally supplies a sensitive existing directory: ```bash ./scripts/safe_clone.sh https://github.com/example/repository "$HOME/Documents" ``` 2. The URL passes GitHub URL validation. 3. The script detects that the selected ta ...[truncated 883 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create and enforce a dedicated clone root, such as: ```bash clone_root="${GITHUB_CLONE_ROOT:-$HOME/.local/share/github-installer/clones}" mkdir -p -- "$clone_root" clone_root="$(realpath -e -- "$clone_root")" ``` 2. Canonicalize the destination and verify that it remains beneath the clone root: ```bash target_parent="$(realpath -m -- "$(dirname -- "$target_dir")")" target_name="$(basename -- "$target_dir")" canonical_target="$target_parent/$target_name" case "$canonical_target" in "$clone_root"/*) ;; *) log_error "Target must be inside $clone_root" return 1 ;; esac ``` 3. Explicitly reject empty paths, `/`, `.`, `..`, the home directory, and the clone root itself. 4. Reject symbolic-link destinations and symbolic-link parent components. 5. Prefer refusing existing non-empty directories rather than deleting them. If replacement is required, only delete directories carrying a tool-created marker file with validated ownership. 6. Create a fresh destination atomically using `mktemp -d` and clone into it. Move it into place only after a successful clone. 7. Never rely solely on an interactive confirmation for destructive filesystem operations. 8. Add automated tests proving that sensitive paths, traversal paths, paths outside the clone root, and symbolic-link destinations are rejected. ]]>
