T09 · Insecure Skill Coding Practices
- Location
SKILL.md:56- Finding
Shell Command Injection Through User-Controlled Title and Heredoc Content
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:56-63
Vulnerability Type: Shell command injection
Risk Level: High
Category:T09: Insecure Skill Coding PracticesVulnerable Code
bash python "SKILL_DIR/scripts/export_word.py" "$HOME/Desktop/文字游戏剧本_<标题>.docx" "<标题>" - <<EOF <这里放生成的Markdown格式剧本内容> EOFTechnical Analysis
The skill instructs the agent to interpolate a user-influenced title and generated Markdown content directly into a shell command. Although the title arguments are shown inside double quotes, shell constructs such as command substitution remain active inside double-quoted strings when the final command text is interpreted by a shell.
The unquoted heredoc delimiter creates an additional injection surface. A generated script containing a line that exactly matches
EOFcan terminate the heredoc prematurely. Any subsequent lines can then be parsed as shell commands rather than document content.The Python exporter does not independently execute shell commands. The vulnerability exists in the documented invocation mechanism required by the skill.
Attack Path
- An attacker asks the agent to generate a game using a malicious title containing shell syntax, such as a command substitution expression.
- Alternatively, the attacker requests generated Markdown containing a standalone
EOFline followed by shell commands. - The agent follows
SKILL.mdand substitutes the title and generated content into the documented shell command. - The command is submitted to a shell.
- The shell evaluates the injected command substitution or treats content after the premature heredoc terminator as commands.
- The injected commands execute with the permissions of the user or agent process running the skill.
Impact Assessment
Successful exploitation can provide arbitrary command execution under the invoking account. The attacker could read files available to tha ...[truncated 338 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not construct shell command strings using user-controlled or generated values.
- Invoke
scripts/export_word.pythrough a process API that accepts an argument array and does not enable shell interpretation. - Pass the document body through the subprocess standard-input API rather than embedding it in a heredoc.
- Derive the output filename from a sanitized title using a strict allowlist of safe characters.
- Remove path separators, control characters, quotes, shell metacharacters, and traversal sequences from generated filenames.
- Resolve and validate the output path before writing, ensuring it remains inside the intended export directory.
- If a shell script is unavoidable, use a randomly generated quoted heredoc delimiter and robust argument escaping; however, a shell-free subprocess call is strongly preferred.
- Add regression tests using titles and content containing quotes, command substitutions, newlines,
EOF, path traversal sequences, and shell metacharacters.
