T09 · Insecure Skill Coding Practices
- Location
SKILL.md:20- Finding
Shell Command Injection Through User-Controlled Message Interpolation
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 20-26
Vulnerability Type: OS command injection caused by unsafe command-string construction
Risk Level: HighVulnerable code:
bash timeout 180 /home/gem/workspace/agent/scripts/dify_router.sh "用户完整消息(含前缀)" "用户open_id"The surrounding instructions explicitly require the complete user-controlled message to be inserted into this command and executed through the
exectool.Technical Analysis
The skill constructs a shell command as a string containing the complete user message. Although the message is shown inside double quotes, double quotes do not prevent shell command substitution such as
$(command)or backtick substitution. The instructions do not require argument-array execution, disabling shell interpretation, or robust shell escaping.If the agent replaces the placeholder with the message verbatim, shell syntax in the message can be evaluated before
dify_router.shreceives its arguments. For example, a triggering message containing$(id)could cause the shell to executeidwhile constructing the script argument. More harmful commands could be substituted depending on the privileges and available tools of the agent process.Attack Path
- An attacker sends a message beginning with the required trigger phrase.
- The remainder of the message contains shell substitution syntax, such as
$(attacker_command). - The agent follows the skill instructions and interpolates the complete message into the documented command string.
- The
exectool invokes a shell to interpret the resulting command. - The shell evaluates the injected substitution before launching
dify_router.sh. - The injected command runs with the operating-system permissions of the agent process.
Impact Assessment
Successful exploitation can provide arbitrary command execution under the account running the agent. Depending on that account's permis ...[truncated 309 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not concatenate user input into a shell command string.
- Invoke the script through an API that accepts an argument array, with shell processing explicitly disabled. Conceptually, use arguments equivalent to:
text ["timeout", "180", "/home/gem/workspace/agent/scripts/dify_router.sh", complete_message, validated_open_id] - If the execution interface only supports command strings, redesign the integration rather than relying on ad hoc escaping.
- Validate
open_idagainst a strict allowlist pattern and length limit. - Apply reasonable message-length limits and reject control characters where they are not needed.
- Run the integration under a dedicated, least-privileged operating-system account with restricted filesystem and network access.
- Add tests using command-substitution characters, quotes, backticks, newlines, and shell metacharacters to confirm that input is passed literally.
