T09 · Insecure Skill Coding Practices
- Location
scripts/migrate_to_hub.sh:142- Finding
Destructive Duplicate Migration Can Irreversibly Delete Skill Contents
- Content
View full analysis
"$BACKUP_DIR/skills_hub_before.txt" 2>/dev/null || true for dir in "${AGENT_SKILL_DIRS[@]}"; do if [[ -d "$dir" ]]; then agent_name=$(basename "$(dirname "$dir")") ls -la "$dir" > "$BACKUP_DIR/${agent_name}_skills_before.txt" 2>/dev/null || true fi done log_info "备份已保存到: $BACKUP_DIR" else log_dry "将创建备份目录: $BACKUP_DIR" fi ``` ```bash # 如果 hub 中已存在真实目录,跳过(保留先到的版本) if [[ -d "$hub_path" ]] && [[ ! -L "$hub_path" ]]; then log_warn " Hub 已存在 $skill_name (真实目录),跳过移动" # 仍然需要把 Agent 目录的替换为链接 if [[ ! -L "$agent_dir/$skill_name" ]]; then log_action " 删除 $agent_dir/$skill_name 并创建链接" if ! $DRY_RUN; then rm -rf "$agent_dir/$skill_name" ln -s "$hub_path" "$agent_dir/$skill_name" fi fi continue fi ``` ### Technical Analysis The migration script describes its initial phase as creating a backup, but it only records `ls -la` directory listings. These text files contain names and metadata, not the contents of the skills being migrated. When a real directory with the same skill name already exists in `~/.skills`, the script treats the Hub version as authoritative. It then executes `rm -rf` against the corresponding real directory in an Agent skill location and replaces it with a symlink. It does not: - Compare the contents of the two directories. - Preserve the discarded Agent version. - Merge divergent files. - Require explicit confirmation. - Verify that the Hub copy is trusted or complete. - Provide rollback data sufficient to restore deleted files. Quoting prevents str ...[truncated 1650 chars]- Remediation
View remediation
