T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/scan_ai_tools.sh:6
- Finding
- Unsafe Shell Initialization and PATH-Based Tool Execution<![CDATA[ ## Vulnerability Details **File Location**: `scripts/scan_ai_tools.sh:6-31`; related mandatory instructions in `SKILL.md:11-29` **Vulnerability Type**: Unsafe shell configuration execution and untrusted executable resolution **Risk Level**: Medium ### Vulnerable Code ```bash # 加载环境变量 [ -f "$HOME/.zshrc" ] && source "$HOME/.zshrc" CONFIG_FILE="$HOME/.ai-cli-config.json" # 要扫描的 AI CLI 工具列表(只检测这三个核心工具) AI_TOOLS=( "gemini:Gemini CLI:Google AI - 网络搜索/问答" "claude:Claude Code:Anthropic AI - 代码/问答" "cursor-agent:Cursor Agent:AI代码编辑器 - 代码生成/调试" ) echo "🤖 AI CLI 工具扫描器" echo "======================" echo "" available_tools=() unavailable_tools=() for tool_info in "${AI_TOOLS[@]}"; do IFS=':' read -r cmd name desc <<< "$tool_info" # 检查命令是否存在 if command -v "$cmd" &> /dev/null; then echo "✅ $name ($cmd) - 已安装" # 测试可用性 - 直接运行帮助命令 if "$cmd" --help &> /dev/null || "$cmd" -h &> /dev/null || "$cmd" --version &> /dev/null || "$cmd" -v &> /dev/null; then ``` The skill documentation explicitly requires this behavior: ```bash source ~/.zshrc command -v gemini command -v claude command -v cursor-agent ``` ### Technical Analysis The scanner sources the user's interactive `.zshrc` file in its current process. Sourcing a shell configuration does not merely import environment variables: every shell command, function definition, alias, command substitution, and external program referenced by the file may execute. After loading the file, the script trusts the resulting `PATH` and invokes executables by short names. Although the tool names themselves are fixed, the executable selected for each name is controlled by `PATH`. A malicious or compromised shell configuration can therefore prepend an attacker-controlled directory containing a forged `gemini`, `claude`, or `cursor-agent` executable. Redirecting output to `/dev/null` does not provide isolation and does not prevent the resolved program from modifying ...[truncated 1261 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not source interactive shell startup files during tool discovery. - Use the scanner's existing sanitized environment or accept explicit executable paths from the user. - If login-shell environment discovery is indispensable, isolate it in a subprocess and extract only a strictly validated `PATH`; do not run the scanner inside that shell. - Resolve each executable to an absolute path before execution. - Validate ownership, permissions, file type, and expected installation directories for resolved executables. - Provide a discovery-only mode that checks file presence without executing candidate programs. - When an availability test is necessary, run it with a minimal environment, timeout, restricted working directory, and operating-system sandbox. - Document that availability testing executes third-party binaries and obtain confirmation before doing so. ]]>
