T09 · Insecure Skill Coding Practices
- Location
scripts/apollo-evolution/evolution.sh:41- Finding
Path Traversal Through Unvalidated Skill Names
- Content
View full analysis
Vulnerability Details
File Location:
scripts/apollo-evolution/evolution.sh, lines 41-59
Vulnerability Type: Path traversal leading to filesystem access outside intended directories
Risk Level: HighVulnerable Code
bash cmd_copy() { local skill_name="$1" local target_dir="${MEMORY_DIR}/${skill_name}" if [ -z "$skill_name" ]; then echo "用法: evolution.sh copy <skill_name>" exit 1 fi local source_dir="${SKILLS_DIR}/${skill_name}" if [ ! -d "$source_dir" ]; then log_error "Skill不存在: ${skill_name}" exit 1 fi # 创建进化目录 mkdir -p "${target_dir}/variants" # 复制原始版本为第0代 local gen0_dir="${target_dir}/variants/gen-000" cp -r "$source_dir" "$gen0_dir"The same unsafe path construction is subsequently used by other commands, including
mutate,select, andstatus.Technical Analysis
The user-controlled
skill_nameargument is concatenated directly withSKILLS_DIRandMEMORY_DIRwithout validation or canonical containment checks:bash local target_dir="${MEMORY_DIR}/${skill_name}" local source_dir="${SKILLS_DIR}/${skill_name}"Quoting these variables prevents shell word splitting and shell metacharacter injection, but it does not prevent filesystem path traversal. A name containing absolute-path-like or parent-directory components such as
../can resolve outside the intended skill or evolution-state directory.The resulting paths are passed to filesystem-modifying operations such as
mkdir -p,cp -r,sed -i, and redirection intogenerations.json. In themutatecommand, the traversed target must have the expectedvariants/gen-*structure, but an attacker able to prepare or identify such a structure can causeSKILL.mdbeneath it to be modified.Attack Path
- The attacker identifies or prepares a directory accessible to the acc ...[truncated 1516 chars]
- Remediation
View remediation
Remediation Suggestions
-
Restrict skill names to a conservative allowlist:
bash validate_skill_name() { local name="$1" [[ "$name" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || { log_error "Invalid skill name" exit 1 } } -
Explicitly reject absolute paths, path separators, empty values,
.and... -
Canonicalize source and destination paths before use and verify containment:
bash source_dir="$(realpath -e -- "${SKILLS_DIR}/${skill_name}")" [[ "$source_dir" == "${SKILLS_DIR}/"* ]] || { log_error "Skill path escapes the skills directory" exit 1 } -
For paths that do not exist yet, canonicalize and verify their existing parent directory before creating them.
-
Apply the same validation centrally before dispatching
copy,mutate,test,select, andstatus. -
Run the script under a minimally privileged account with write access limited to the intended evolution-state directory.
-
