T09 · Insecure Skill Coding Practices
- Location
SKILL.md:87- Finding
Command Injection Through Unsafe eval-Based Path Expansion
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 87–98
Vulnerability Type: Shell command injection
Risk Level: Highbash # Specify the base directory (may be changed per task) base_dir="~/Downloads" # Inputs (extracted from the page or supplied as task parameters) topo_name="{topology name}" file_name="{file name}" # Sanitize the topology name to avoid invalid path characters safe_topo=$(echo "$topo_name" | tr '/:' '_' | tr -s ' ' '_' | sed 's/[^[:alnum:]_.-]/_/g') # Current time (Asia/Shanghai) now=$(TZ=Asia/Shanghai date +%Y%m%d_%H%M%S) out_dir=$(eval echo "$base_dir")/${safe_topo}_${now}Technical Analysis
The documented template describes
base_diras configurable per task and expands it usingeval. Unlike ordinary parameter expansion,evalreparses its argument as shell syntax. Shell substitutions, metacharacters, or command separators embedded in an attacker-controlled base-directory value can consequently be executed.Quoting
"$base_dir"before it reachesevaldoes not prevent this issue becauseevalperforms an additional parsing pass. The use ofevalis unnecessary when the intended behavior is merely to resolve the user's home directory.Attack Path
- An attacker supplies or influences the task's base-directory parameter.
- The value contains shell syntax, such as
$(id > /tmp/skill-proof). - The Agent substitutes that value into
base_dirand executes the mandatory shell template. eval echo "$base_dir"reparses and executes the embedded command.- Any command available to the Agent can run with the operating-system privileges of the Agent process.
Impact Assessment
Successful exploitation permits arbitrary command execution as the user running the Agent. This can allow reading or modifying user-accessible files, accessing locally available credentials, altering downloaded artifacts, invoking network tools, or executing addi ...[truncated 168 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
evalcompletely. - Use an explicitly expanded path such as
base_dir="$HOME/Downloads". - If a caller may choose the directory, require an absolute path and validate it against an allowlisted parent directory.
- Resolve and verify the canonical path before creating files, rejecting paths that escape the authorized download root.
- Keep all variable expansions quoted and terminate option parsing with
--where supported.
A safer pattern is:
bash base_dir="$HOME/Downloads" mkdir -p -- "$base_dir" base_real=$(realpath -- "$base_dir") allowed_real=$(realpath -- "$HOME/Downloads") case "$base_real/" in "$allowed_real/"*) ;; *) echo "Base directory is outside the permitted root" >&2; exit 1 ;; esac- Remove
