T09 · Insecure Skill Coding Practices
- Location
SKILL.md:122- Finding
Potential shell command injection through unquoted keyword substitution
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:122-125
Vulnerability Type: Shell command injection
Risk Level: HighVulnerable code:
bash # With a category keyword python scripts/fetch_xhs_trends.py --keyword <关键词> --start-date <日期> # Without a category keyword python scripts/fetch_xhs_trends.py --keyword "" --start-date <日期>Technical Analysis
The Skill instructs the Agent to extract a keyword from user input and substitute it into a shell command. The keyword placeholder in the documented command is not quoted, and the instructions do not require use of a structured process API that bypasses shell parsing.
If an Agent constructs and executes this command through a shell, a keyword containing shell metacharacters such as command separators, substitutions, redirections, or pipelines may be interpreted as shell syntax rather than as a single argument. Python's
argparsedoes not mitigate this issue because exploitation occurs in the shell before the Python process receives its arguments.The Python script itself does not invoke a shell. The vulnerability is in the Skill's command-construction instructions and therefore depends on the host Agent interpolating user input into the documented command.
Attack Path
- An attacker submits a title-generation request containing a keyword with embedded shell syntax.
- The Agent extracts that attacker-controlled text as the keyword.
- Following
SKILL.md, the Agent substitutes the keyword directly into the unquoted command template. - The Agent executes the constructed string through a shell.
- The shell parses the injected syntax and executes attacker-selected commands in addition to the intended Python script.
Impact Assessment
Successful exploitation could execute arbitrary local commands with the same operating-system privileges as the Agent. Depending on those privileges, the attacker could read or modif ...[truncated 268 chars]
- Remediation
View remediation
Remediation Suggestions
- Require invocation through a process API using an argument array, with shell execution disabled. For example:
python subprocess.run( [ sys.executable, "scripts/fetch_xhs_trends.py", "--keyword", keyword, "--start-date", start_date, ], shell=False, check=True, ) - If a shell command must be displayed for manual use, require platform-appropriate escaping and quote every substituted argument.
- Validate
start-dateagainst a strictYYYY-MM-DDformat before invocation. - Reject control characters and document that user-derived values must never be concatenated into executable command strings.
- Prefer calling
fetch_xhs_trends()directly from Python rather than launching a subprocess.
- Require invocation through a process API using an argument array, with shell execution disabled. For example:
