T09 · Insecure Skill Coding Practices
- Location
SKILL.md:65- Finding
Arbitrary Python Code Execution Through Unsafe Task Interpolation
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 65-71
Vulnerability Type: Python source-code injection
Risk Level: HighVulnerable Code
python # Generate and execute this Python script (fill in `{address}` and `{task}`): import sys, json, time, uuid, asyncio import httpx, websockets from connectonion import address from pathlib import Path TARGET = "{address}" TASK = "{task}"Technical Analysis
The skill directs the Agent to generate executable Python source by replacing the
{address}and{task}placeholders with values derived from the user's message. In particular, the task description is unrestricted text and is inserted directly inside a quoted Python string.No escaping or safe serialization is required before the resulting script is executed through the shell tool. A task containing quotation marks, line breaks, backslashes, or Python syntax can therefore terminate the intended string literal and introduce additional statements.
This is a source-code injection vulnerability rather than ordinary task delegation. Merely validating the target address does not protect the
TASKassignment because the remaining user message is treated as the task description.Attack Path
- An attacker sends an
/oorequest containing a syntactically valid ConnectOnion address. - The task description includes characters that terminate the
TASKstring literal, followed by attacker-controlled Python statements. - The Agent substitutes that task directly into
TASK = "{task}". - The Agent executes the generated script using its shell tool, as required by the skill.
- The injected statements execute with the same operating-system privileges, filesystem access, network access, and environment access as the Agent process.
Impact Assessment
Successful exploitation provides arbitrary Python code execution in the Agent's environment. The attacker may read or modify fil ...[truncated 450 chars]
- An attacker sends an
- Remediation
View remediation
Remediation Suggestions
Do not generate executable source code by interpolating user-controlled values.
- Store the script as static, reviewed code.
- Pass the address and task through command-line arguments, standard input, or a JSON data file.
- If source generation is unavoidable, serialize values with a correct data serializer such as
json.dumpsorrepr; however, separating code from data remains the preferred design. - Validate the target address against the documented full-match expression before passing it to the script.
- Treat the task as opaque data and impose reasonable length limits.
- Execute networking logic in a restricted subprocess with minimal filesystem access, a sanitized environment, and no unnecessary credentials.
- Add tests containing quotes, backslashes, multiline content, and attempted Python statements to verify that task data cannot alter program structure.
A safer interface would read JSON from standard input:
python request = json.load(sys.stdin) target = request["address"] task = request["task"]The caller should then send serialized JSON without embedding either value into Python source.
