T09 · Insecure Skill Coding Practices
- Location
scripts/gen.py:378- Finding
API Token Exposure Through Command-Line Arguments
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This skill appears to generate images through ModelScope as advertised, but it handles API keys and downloads provider-supplied URLs with insufficient safeguards.
Review before installing. Use an environment variable or secret manager for MODELSCOPE_API_KEY, avoid the --api-key command-line option, do not send sensitive or confidential prompts, and prefer running it in an environment where outbound network access and output size are constrained.
scripts/gen.py:378API Token Exposure Through Command-Line Arguments
scripts/gen.py:457Unrestricted Retrieval of API-Controlled Image URLs
Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.
)
try:
with urllib.request.urlopen(req, timeout=30) as resp:
result = json.loads(resp.read().decode("utf-8"))
task_status = result.get("task_status", "")
Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.
)
try:
with urllib.request.urlopen(req, timeout=300) as resp:
response = json.loads(resp.read().decode("utf-8"))
# 检查是否为异步任务
The skill invokes a Python script that reads environment variables, reads local reference files, writes output files, and makes outbound network requests, but the manifest does not declare any explicit tool scope or allowed-tools boundary. This weakens least-privilege controls and makes it harder for a host agent or reviewer to understand and constrain what the skill is permitted to access.
L003 明确写明“根据用户需求由 AI 生成专业的提示词”,并将技能定位为“中文 AI 模型生成图片”场景;结合全文示例和长度规则均以中文提示词为默认,没有说明用户可选择英文或其他语言。若无用户明确同意或业务上的区域限定,这属于语言/locale 强制约束。
The skill states it will generate prompts and call an external API, which means user-supplied content may be transmitted to a third party, yet it does not clearly warn users about that transfer at the point the workflow is introduced. In a skill that may process creative requests containing personal or sensitive details, lack of explicit disclosure can lead to unintended privacy exposure.
L033-L037 的“当出现以下情况时使用本技能”包含“用户需要专业优化的提示词来生成高质量图片”等宽泛条件,未明确限定必须是 ModelScope/魔搭社区相关请求时才触发。对于清单中第三条,这可能与大量普通文生图或提示词优化场景重叠,导致技能被过度调用。
The document instructs users to place a bearer API token into requests sent to an external service, but it does not explicitly warn that this transmits credentials off-platform or advise safe secret handling. In an agent skill context, users may not realize the token is sensitive operational data, increasing the risk of accidental disclosure through logs, screenshots, copied commands, or misuse in untrusted environments.
文档在 L007-L016 明确声明正确端点为 https://api-inference.modelscope.cn/v1/images/generations,但后续 Python、cURL、urllib 示例在 L196、L216、L233 使用了 https://api-inference.modelscope.cn/api/v1/images/generations。这不是单纯的信息遗漏,而是文档内部对同一关键调用目标给出了互相冲突的指导,可能直接导致实现者调用错误接口。
This example performs an outbound HTTP request to a remote service using a bearer token. In the context of an agent skill, external transmission is security-relevant because prompts and credentials may leave the local environment, and without prominent disclosure users may unknowingly send sensitive data to a third party.
"size": "1024x1024" }
response = requests.post(url, headers=headers, json=data) result = response.json() print(result)
The cURL example shows direct transmission of a bearer token to a third-party endpoint from a shell command, which is prone to accidental disclosure through shell history, process inspection, screenshots, or copied terminal output. In a skill meant to guide users, this is dangerous if presented without warnings or safer secret-handling practices.
print(result)
### cURL 示例
```bash
curl -X POST https://api-inference.modelscope.cn/api/v1/images/generations \
The retry example repeatedly sends requests to an external service and may retransmit prompt content and credentials multiple times. In an agent setting, repeated external transmission amplifies privacy and operational risk, especially if prompts contain confidential data or if retries are not clearly disclosed to the user.
def call_api_with_retry(prompt, max_retries=3):
for attempt in range(max_retries):
try:
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
return response.json()
elif response.status_code == 429:
This markdown file presents all instructions and model-selection guidance only in Chinese, including the usage note and headings. Under the policy rule for natural-language violations, forcing a specific language without user opt-in can exclude users who do not read that language, and the file does not state that it is intentionally region-specific.
The entire guide is written in Chinese and presents itself as a general-purpose prompt guide, but it does not indicate that Chinese is optional, user-selected, or required for a specific regional compliance reason. This can violate language/locale policy when a skill implicitly constrains users to one language without opt-in.
L197-L201 将提示词长度控制写成“中文 20-50 字”,呈现为默认且唯一的语言规范,没有提供英文等其他语言的可选规则。这会把技能行为绑定到单一语言习惯,缺少用户语言偏好选择。
The document explains how to supply an API key and use bearer authentication but does not explicitly warn against exposing the credential in logs, shell history, shared terminals, or generated artifacts. While this is common operational guidance, omitting credential-handling precautions increases the risk of accidental secret leakage.
All headings, instructions, and examples are presented in Chinese, which effectively imposes a specific language on users. The policy allows locale constraints only when users are given a choice or when the restriction is explicitly justified, neither of which appears in this file.
Detected: suspicious.exposed_secret_literal