T09 · Insecure Skill Coding Practices
- Location
SKILL.md:25- Finding
Python Code Injection Through the AGENT_NAME Environment Variable
- Content
View full analysis
/dev/null) app_secret=$(python3 -c " import json, sys c = json.load(open('$config_file')) accounts = c.get('channels', {}).get('feishu', {}).get('accounts', {}) if '$agent_name' in accounts: print(accounts['$agent_name'].get('appSecret', '')) elif 'main' in accounts: print(accounts['main'].get('appSecret', '')) else: print('') " 2>/dev/null) echo "$app_id $app_secret" } ``` ### Technical Analysis The environment-controlled `AGENT_NAME` value is expanded by the shell directly into two Python programs passed to `python3 -c`. The value is placed inside Python string literals without any escaping or validation: ```python if '$agent_name' in accounts: ``` An attacker who can control `AGENT_NAME` can supply quote characters, line breaks, and Python statements that terminate the intended string and alter the generated program. The resulting statements are evaluated by `python3` with the same operating-system privileges and environment as the agent. This is not limited to selecting another Feishu account. Successful injection can invoke Python modules such as `os` or `subprocess`, read local files, modify files accessible to the agent, or start arbitrary commands. The code is executed twice be ...[truncated 1517 chars]- Remediation
View remediation
