T09 · Insecure Skill Coding Practices
- Location
SKILL.md:53- Finding
Command Injection Risk Through Untrusted Hazard Description Interpolation
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 53-56
Vulnerability Type: Command injection through unsafe shell-command construction
Risk Level: HighComplete Vulnerable Code Snippet:
markdown **Step 1:** Run the stop-work check FIRST, before any other analysis:text python3 /sandbox/skills/msha-compliance/check_stopwork.py "[hazard description]"Technical Analysis
The documented command places an attacker-controlled hazard description directly inside a shell command. Double quotes do not safely neutralize embedded quote characters or shell metacharacters. If the agent executes this template through a shell, a crafted description can terminate the quoted argument and append an arbitrary command.
The Python script itself does not invoke a shell and safely reads its arguments from
sys.argv. The vulnerability is in the skill instruction that tells the agent how to construct the invocation. Exploitability therefore depends on whether the agent's execution tool passes the rendered command through a shell. An argument-array invocation without a shell would not be vulnerable.Attack Path
-
An attacker submits a hazard report containing a closing quote and shell syntax.
-
The skill directs the agent to substitute that report into the quoted command template.
-
The agent renders a command conceptually equivalent to:
text python3 /sandbox/skills/msha-compliance/check_stopwork.py ""; ATTACKER_COMMAND; #" -
If a shell interprets the rendered text, it runs
ATTACKER_COMMANDafter invoking the safety script. -
The injected command executes with the same operating-system identity and sandbox permissions as the agent process.
Impact Assessment
Successful exploitation provides arbitrary command execution within the agent's execution environment. The attacker could read or modify files available to the agent, access environment variables and loca ...[truncated 365 chars]
-
- Remediation
View remediation
Remediation Suggestions
-
Do not build a shell command by interpolating the hazard description.
-
Invoke the program with a structured argument array and disable shell interpretation. For example:
python subprocess.run( ["python3", script_path, hazard_description], shell=False, check=True, capture_output=True, text=True, ) -
Update
SKILL.mdto require a tool interface with separate executable and argument fields rather than displaying a textual shell command. -
Validate that
script_pathis a fixed, trusted path and is not derived from user input. -
Apply a reasonable maximum length to hazard descriptions to reduce resource-abuse risk.
-
If the platform only exposes a shell interface, use a platform-maintained argument-escaping function and pass the description through a protected channel such as standard input. Do not implement ad hoc escaping.
-
Add regression tests containing quotes, semicolons, command substitutions, newlines, and other shell metacharacters, verifying that they are delivered as one literal argument.
-
