T09 · Insecure Skill Coding Practices
- Location
SKILL.md:42- Finding
Shell Command Injection Through Interpolated Error Record Fields
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 42–50
Vulnerability Type: Shell command injection
Risk Level: HighVulnerable Code
markdown **User did not solve the problem**: 1. Ask the user to provide the reason for the error 2. After receiving the reason, automatically generate: - **Core idea** - **Similar problems** 3. Invoke the script to record the entry in `errorset.md`: ```bash python3 scripts/manage_errors.py add <day> "<problem ID>" "<problem title>" "<type>" "<error reason>" "<core idea>" "<similar problems>"text The source text is presented in Chinese in the audited file; the excerpt above is an English translation that preserves the command exactly in escaped XML form. ### Technical Analysis The workflow asks the user to provide an error reason and instructs the agent to interpolate it into a shell command. Other values may also originate from user input or model-generated content. Enclosing these values in double quotes does not make them safe for shell execution: command substitutions such as `$(command)` and backtick substitutions are still evaluated by POSIX-compatible shells. Consequently, if the agent follows this instruction by passing the assembled command to a shell, specially crafted field content can cause an arbitrary command to run before `manage_errors.py` starts. The Python implementation in `scripts/manage_errors.py` does not itself invoke a shell; it reads positional arguments from `sys.argv`. The vulnerability therefore resides in the command-construction procedure documented by the Skill, not in Python argument parsing. ### Attack Path 1. An attacker triggers the workflow by reporting that a problem was not solved. 2. When asked for an error reason, the attacker supplies shell syntax, for example: ```text $(touch /tmp/skill-pwned)- The agent follows the Skill instruction and constructs a command resembling:
bash
...[truncated 1274 chars]
- The agent follows the Skill instruction and constructs a command resembling:
- Remediation
View remediation
Remediation Suggestions
-
Do not assemble a shell command from conversation-derived values. Launch the script with a process API that accepts an argument array, for example:
python subprocess.run( [ "python3", "scripts/manage_errors.py", "add", day, problem_id, title, error_type, reason, core_idea, similar, ], check=True, shell=False, ) -
Prefer structured input over positional shell arguments. Accept a JSON document through standard input, validate its schema in
manage_errors.py, and write only validated fields:json { "day": 1, "problem_id": "977", "title": "Sorted Squares", "type": "Array", "reason": "Incorrect pointer update", "core_idea": "Use two pointers", "similar": "88, 75" } -
Validate input types and lengths. Require
dayto be an integer in the expected schedule range, constrain text-field lengths, and reject control characters where they are unnecessary. -
If shell execution cannot be avoided, use a proven platform-specific escaping mechanism for every dynamic argument. Simple quoting, character replacement, or blacklisting is insufficient. Structured execution with
shell=Falseremains the preferred fix. -
Update
SKILL.mdto prohibit shell interpolation explicitly. Document that user-controlled and model-generated fields must be passed as discrete process arguments or through standard input. -
Add regression tests containing payloads such as
$(touch /tmp/test), backticks, quotes, semicolons, newlines, and redirection operators, and verify that they are stored strictly as text without executing commands.
-
