T09 · Insecure Skill Coding Practices
Warning
- Location
- install.sh:3
- Finding
- Configuration is created and deleted outside the skill directory<![CDATA[ ## Vulnerability Details **File Locations**: - `install.sh:3-4, 19-30` - `uninstall.sh:3-4, 8-17` - `source/meeting_helper.py:16-17` **Vulnerability Type**: Incorrect path resolution and unsafe configuration deletion **Risk Level**: Medium ### Vulnerable Code ```bash # install.sh SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BASE_DIR="$(dirname "$SCRIPT_DIR")" if [ ! -f "$BASE_DIR/.env" ]; then echo "📝 创建 .env 配置文件..." cat > "$BASE_DIR/.env" << 'EOF' # OpenAI API Configuration OPENAI_API_KEY=your-api-key-here # 可选:使用代理 # HTTP_PROXY= # HTTPS_PROXY= EOF echo "⚠️ 请编辑 $BASE_DIR/.env 文件,填入你的 OPENAI_API_KEY" fi ``` ```bash # uninstall.sh SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BASE_DIR="$(dirname "$SCRIPT_DIR")" read -p "是否删除配置文件和备份数据?(y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then rm -f "$BASE_DIR/.env" rm -rf "$BASE_DIR/.ai_meeting_backup" rm -rf "$BASE_DIR/.ai_meeting_logs" echo "✅ 已删除配置和备份" fi ``` ```python # source/meeting_helper.py BASE_DIR = Path(__file__).parent.parent load_dotenv(BASE_DIR / ".env") ``` ### Technical Analysis The shell scripts are located in the project root. Consequently, `SCRIPT_DIR` is already the project directory, while `BASE_DIR="$(dirname "$SCRIPT_DIR")"` resolves to its parent. The installer therefore creates `.env`, `.ai_meeting_backup`, and `.ai_meeting_logs` in the parent workspace rather than inside the skill. The Python application calculates its base directory differently: the parent of `source/` is the project root. It attempts to load `.env` from the project itself, not from the parent directory used by the installer. This mismatch can cause configuration failure and may encourage users to place an API key in an unintended shared workspace file. The uninstaller uses the same incorrect shell path and can remove the parent directory's `.env` after a generic confirmation. That file may belong to another project or contain unrelated credentials ...[truncated 1257 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Treat the script directory as the project base directory: ```bash SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BASE_DIR="$SCRIPT_DIR" ``` 2. Use the same base-directory definition consistently in installation, uninstallation, and runtime code. 3. Keep `.env`, backups, and logs in clearly skill-owned paths beneath the project directory. 4. Before deleting data, display the fully resolved paths and request confirmation for those exact paths. 5. Add a defensive path-boundary check before recursive deletion: ```bash case "$TARGET" in "$SCRIPT_DIR"/*) rm -rf -- "$TARGET" ;; *) echo "Refusing to delete path outside the skill directory" >&2; exit 1 ;; esac ``` 6. Use `--` before path operands passed to `rm` and other filesystem utilities. 7. Restrict the credential file to the current user after creation: ```bash chmod 600 "$BASE_DIR/.env" ``` ]]>
