T09 · Insecure Skill Coding Practices
- Location
scripts/forge.py:1154- Finding
Shell Command Injection Through an Unvalidated Skill Name
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This skill has a coherent GitHub-to-agent-skill purpose, but it handles local files, secrets, mirrors, and shell commands too broadly for automatic installation.
Install only if you are prepared to review and constrain it. Run it in an isolated workspace, avoid using --force, provide only simple basename skill names, do not run it from a directory containing secrets in .env, prefer official GitHub sources over mirrors, and manually review generated context and SKILL.md before installing dependencies or executing cloned code. I do not see artifact-backed deception or exfiltration, so this is Review rather than malicious.
scripts/forge.py:1154Shell Command Injection Through an Unvalidated Skill Name
scripts/forge.py:1438Path Traversal Enables Filesystem Writes and Recursive Directory Deletion Outside the Output Root
scripts/forge.py:151Unverified Third-Party Mirrors Can Substitute Repository Source and Metadata
scripts/forge.py:1353Untrusted Repository Content Is Inserted Verbatim Into Agent-Consumed Context
scripts/forge.py:16Automatic Loading of Arbitrary Local Environment Variables Expands Secret Exposure
Referenced artifact was not completely inspected
# 语法: python scripts/forge.py <URL> [SKILL_NAME]
Referenced artifact was not completely inspected
# 语法: python scripts/forge.py <URL> [SKILL_NAME]
The documented remediation uses rm -rf .trae/skills/xxx, which is a destructive shell pattern that can delete directories recursively. In the context of a skill that accepts user-supplied repository URLs and skill names and instructs agents to manipulate filesystem paths, this is especially risky because path confusion, substitution mistakes, or automation errors could lead to unintended data loss.
2. 或手动删除已存在的目录后重试
```bash
rm -rf .trae/skills/xxx
This line marks the start of .env-loading behavior that can absorb local credentials into the process environment. In a repository-processing skill, automatically collecting secrets from the operator's filesystem is more dangerous because later network and subprocess operations may consume them unexpectedly.
import urllib.error
from pathlib import Path
# 尝试加载本地 .env 文件
def load_env_file(env_path: Path):
"""
轻量级加载 .env 文件到环境变量
The .env-loading routine is part of credential-access behavior because it reads locally stored secrets from developer-controlled files. Even without immediate exfiltration at this line, it broadens access to sensitive data beyond what the tool strictly needs.
# 尝试加载本地 .env 文件
def load_env_file(env_path: Path):
"""
轻量级加载 .env 文件到环境变量
"""
if not env_path.exists():
return
Enumerating multiple possible .env locations increases the chance of collecting unrelated credentials from parent and current working directories. This is especially risky for a general-purpose automation tool that may be run inside many different projects.
except Exception:
pass
# 加载脚本同目录或父目录下的 .env
env_paths = [
Path(__file__).parent / ".env",
Path(__file__).parent.parent / ".env",
The code targets the script directory's .env file as a credential source, contributing to broad secret ingestion behavior. Because the skill is distributed automation, users may not expect execution to read nearby secret files automatically.
# 加载脚本同目录或父目录下的 .env
env_paths = [
Path(__file__).parent / ".env",
Path(__file__).parent.parent / ".env",
Path.cwd() / ".env"
]
The code targets the parent directory's .env file, expanding credential access outside the immediate script directory. This scope creep materially raises the chance of pulling in unrelated secrets from a broader workspace.
# 加载脚本同目录或父目录下的 .env
env_paths = [
Path(__file__).parent / ".env",
Path(__file__).parent.parent / ".env",
Path.cwd() / ".env"
]
for env_p in env_paths:
Loading a .env file from the current working directory is risky because the working directory is highly variable and may contain unrelated project secrets. In a tool that also performs network requests and subprocess calls, this increases the potential blast radius of local credential exposure.
env_paths = [
Path(__file__).parent / ".env",
Path(__file__).parent.parent / ".env",
Path.cwd() / ".env"
]
for env_p in env_paths:
load_env_file(env_p)
The script reads GITHUB_TOKEN from the environment and includes it in an Authorization header for API requests to matching github.com mirror bases. This is a sensitive credential use combined with network transmission, but there is no explicit user disclosure that the token may be used for outbound requests.
When force mode is enabled, the script recursively deletes the target directory without an interactive confirmation or strong path safety checks. If the output path or skill name is mistaken or manipulated, this can destroy unintended local data on the operator's system.
The script executes shell commands to clone repositories using a command string and shell=True, giving the tool generic command-execution capability. Because this skill processes untrusted repository URLs and paths, the shell usage materially increases the chance of command injection or unsafe execution beyond the stated purpose.
The script executes a shell command assembled from repository and filesystem inputs without adequately warning the user that shell execution will occur. In this tool's context, users may expect repository conversion, not shell-mediated command construction, making misuse or injection more dangerous.
This subprocess invocation uses shell=True unnecessarily for a fixed command, which is a form of unsafe tool parameter usage. It does not appear directly exploitable via user input here, but it establishes insecure execution patterns and reliance on shell semantics.
# 尝试使用 shell=True 并直接拼接字符串(注意安全,这里 clone_url 是可控的)
# 检查 git 是否可用
try:
subprocess.run(["git", "--version"], capture_output=True, check=True, shell=True)
cmd_str = f'git clone --depth {config.clone_depth} "{clone_url}" "{target_dir}"'
except:
# 如果 git 失败,尝试完全限定路径或报错
This call executes a shell command built from external and filesystem-derived values, creating a classic parameter-abuse and command-injection risk. Because the tool is designed to handle arbitrary GitHub repositories, treating those parameters as shell-safe is especially dangerous in context.
cmd_str = f'git clone --depth {config.clone_depth} "{clone_url}" "{target_dir}"'
print(f"{Colors.INFO}执行命令: {cmd_str}")
result = subprocess.run(
cmd_str, capture_output=True, text=True, timeout=config.timeout, shell=True
)
The skill describes capabilities that include shell, network, file read/write, and environment access, but it does not declare any explicit tool scope or permission boundaries. For a meta-skill that clones repositories, generates files, and runs commands, this omission is dangerous because it can cause an agent to apply the skill with overly broad authority and insufficient user awareness.
The invocation phrases are broad enough that ordinary user requests like 'I want to use this GitHub repo' could trigger the skill automatically. Because this skill performs repository cloning, file creation, dependency handling, and validation commands, accidental triggering increases the chance of unreviewed code intake and command execution.
Skill enumerates or reads other installed skills. Access to other skills' SKILL.md files or the skills directory reveals prompt instructions, capabilities, and secrets that should be invisible to peer skills.
3. Agent 编辑 SKILL.md
edit .trae/skills/sqlmap/SKILL.md
4. Agent 运行验证
The skill includes installation guidance using privileged commands such as sudo apt install fzf. In a skill that already encourages agents to scaffold and validate external tools, recommending privileged execution raises the risk of system-wide changes or package installation without adequate trust review, especially when the source repository is untrusted.
brew install fzf
# Linux
sudo apt install fzf
# Windows
choco install fzf
The best-practices section explicitly instructs generated SKILL.md files to '使用中文标题,英文命令', which imposes a specific language choice. This is a natural-language locale policy constraint and the file does not indicate that users may choose another language or opt in to Chinese output.
The script automatically loads .env files from multiple nearby directories into process environment variables without explicit user consent. This can ingest unrelated secrets present in the working directory or parent directories and make them available to later network logic, which is broader than required for converting repositories into skills.
Secret-bearing .env files are loaded silently with no user-facing warning, which creates an informed-consent and data-minimization problem. In a developer environment, this can unexpectedly expose credentials to subsequent logic or child processes even if the user only intended repository analysis.
The generated template systematically translates descriptions into Chinese and emits the skill content entirely in Chinese, including role, invocation guidance, and workflow steps. This imposes a specific language/locale behavior without offering the user a language choice or documenting it as a justified regional constraint.
Using subprocess.run with shell=True for a simple git --version check is unnecessary and normalizes shell-based execution in the codebase. While this specific invocation is not directly attacker-controlled, it increases attack surface and can behave unexpectedly across platforms or with modified shell environments.
# 尝试使用 shell=True 并直接拼接字符串(注意安全,这里 clone_url 是可控的)
# 检查 git 是否可用
try:
subprocess.run(["git", "--version"], capture_output=True, check=True, shell=True)
cmd_str = f'git clone --depth {config.clone_depth} "{clone_url}" "{target_dir}"'
except:
# 如果 git 失败,尝试完全限定路径或报错
The script builds a shell command string containing repository-derived data and executes it with shell=True. Although URLs are nominally validated, other interpolated values such as target_dir and clone_url can still introduce shell metacharacter risk, and shell invocation is unnecessary for git clone here. In a skill-forging tool that processes external repository inputs, this expands a repository conversion task into arbitrary command execution if inputs are manipulated.
cmd_str = f'git clone --depth {config.clone_depth} "{clone_url}" "{target_dir}"'
print(f"{Colors.INFO}执行命令: {cmd_str}")
result = subprocess.run(
cmd_str, capture_output=True, text=True, timeout=config.timeout, shell=True
)