T09 · Insecure Skill Coding Practices
- Location
SKILL.md:45- Finding
Unvalidated Role Names May Enable Path Traversal or Shell Command Injection
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:45-50,SKILL.md:56-62, andSKILL.md:120-124; related input format inTEMPLATE.md:6-9
Vulnerability Type: Improper validation of user-controlled filesystem and command input
Risk Level: HighVulnerable Code Snippets
SKILL.md:45-50:text 创建角色 {角色名}: {核心职责描述}text 会在 `workspace/agents/{角色名}/` 下自动创建: - `profile.md` - 角色设定 - `memory.md` - 长期记忆 - `current.md` - 当前状态SKILL.md:56-62:text 启动 {角色名} 启动 {角色名} 执行 {任务描述}text 1. 解析角色名(支持别名匹配) 2. 检查 `agents/{角色}/` 是否存在SKILL.md:120-124:text 本 skill 内部使用: - `exec ls` - 检查角色目录是否存在 - `exec mkdir` - 创建角色目录 - `read/write` - 读写记忆文件TEMPLATE.md:6-9:text ## 命令格式创建角色 {角色名}: {核心能力}; {工作风格}; {偏好}; {注意事项}
text Technical Analysis
The skill accepts a role name from a user command and incorporates that value into a path below
workspace/agents/. It also explicitly instructs the agent to use shell-backedexec lsandexec mkdiroperations when checking and creating role directories.The documented process does not require any of the following safeguards:
- A strict allowlist for role-name characters.
- Rejection of absolute paths or
..traversal components. - Canonical-path validation against the intended
workspace/agentsroot. - Shell-safe argument handling.
- Use of structured filesystem operations instead of command-string construction.
If an implementation directly concatenates the supplied role name into a shell command, shell metacharacters could introduce additional commands. Even where shell metacharacters are safely quoted, directory separators and traversal components could cause reads or writes outside the intended role directory.
The exact exploitability depends on how the runtime translates these natural-language instructions into tool calls. The unsafe data flow is nevertheless ...[truncated 1742 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict role names to a short identifier allowlist, such as
^[A-Za-z0-9_-]{1,64}$. - Reject empty names,
.and.., path separators, absolute paths, control characters, whitespace, command substitutions, redirection operators, and shell metacharacters. - Resolve the candidate directory to a canonical path and verify that it remains a descendant of the canonical
workspace/agentsdirectory. - Use structured filesystem APIs for existence checks and directory creation rather than
exec lsandexec mkdir. - If command execution is unavoidable, pass arguments as an array without invoking a shell. Do not interpolate the role name into a command string.
- Apply the same validation to aliases loaded from
ROLES.md; aliases must not bypass role-name restrictions. - Refuse reads or writes involving symbolic links that resolve outside the approved workspace.
- Add negative tests covering
../, absolute paths, separators, command substitutions, redirection, quotes, newlines, and symbolic-link escapes.
- Restrict role names to a short identifier allowlist, such as
