T09 · Insecure Skill Coding Practices
- Location
SKILL.md:37- Finding
API Key Exposure Through Documented Plaintext File Output
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This skill performs the advertised customs-data query, but it also exposes and persists API credentials in risky ways and includes account/payment and hidden update-check behavior that users should review before installing.
Install only if you are comfortable with this skill using an UpKuaJing API key, making paid API calls after confirmation, and handling account/top-up flows. Do not let an agent print ~/.upkuajing/.env; store the key with restrictive permissions or a secret manager, review any payment URL before opening it, and only approve error reports after removing sensitive request or response details.
SKILL.md:37API Key Exposure Through Documented Plaintext File Output
scripts/auth.py:24API Key Stored Without Explicit Restrictive Permissions and Partially Disclosed
requirements.txt:1Unbounded and Unhashed Third-Party Dependency Installation
The skill also performs remote version checks, reads local metadata, and writes a version cache in the user's home directory despite being presented as an analytics tool. Hidden update-check and local state behavior broadens the attack surface and introduces additional network and filesystem side effects that users may not expect from a read-mostly query skill.
The skill also performs remote version checks, reads local metadata, and writes a version cache in the user's home directory despite being presented as an analytics tool. Hidden update-check and local state behavior broadens the attack surface and introduces additional network and filesystem side effects that users may not expect from a read-mostly query skill.
The skill also performs remote version checks, reads local metadata, and writes a version cache in the user's home directory despite being presented as an analytics tool. Hidden update-check and local state behavior broadens the attack surface and introduces additional network and filesystem side effects that users may not expect from a read-mostly query skill.
The skill instructs access to a credential file in the user's home directory and shows a command to print its contents. In an agent setting, normalizing direct reads of .env files is dangerous because it can expose API secrets to logs, model context, or unintended outputs far beyond what is needed to verify configuration.
This skill requires an API key. The API key is stored in the ~/.upkuajing/.env file:
cat ~/.upkuajing/.env
Example file content:
This workflow directs the agent to inspect a local .env file for API credentials and, if missing, to invoke a command that creates a new key and stores it automatically. Combining credential discovery, generation, and storage within a data-query skill materially increases privilege and creates risk of unauthorized secret handling or persistence on disk.
### **API Key Not Set**
First check if the `~/.upkuajing/.env` file has UPKUAJING_API_KEY;
If UPKUAJING_API_KEY is not set, prompt the user to choose:
1. User has one: User provides it (manually add to ~/.upkuajing/.env file)
2. User doesn't have one: You can apply using the interface (`auth.py --new_key`), the new key will be automatically saved to ~/.upkuajing/.env
Wait for user selection;
The skill tells the user to manually add an API key to a local .env file and supports automatic persistence of newly created keys there. Storing and handling secrets in plain-text home-directory files is risky in shared or agent-accessible environments, and the skill context makes this more dangerous because the same skill also uses file-read capabilities that could expose those credentials.
First check if the `~/.upkuajing/.env` file has UPKUAJING_API_KEY;
If UPKUAJING_API_KEY is not set, prompt the user to choose:
1. User has one: User provides it (manually add to ~/.upkuajing/.env file)
2. User doesn't have one: You can apply using the interface (`auth.py --new_key`), the new key will be automatically saved to ~/.upkuajing/.env
Wait for user selection;
### **Account Top-up**
This file implements account administration functions such as API key issuance, balance lookup, pricing lookup, and recharge-order creation, which are unrelated to the declared HS-code trade-statistics purpose. In a skill context, this scope expansion is dangerous because it grants billing and credential-management capabilities that a data-analysis skill should not need, increasing the blast radius if the skill is invoked or repurposed unexpectedly.
This finding points to handling of a .env file in a credential-management path. Reading and checking for existing API secrets in a local plaintext environment file is risky because such files are commonly exposed through weak permissions, backups, developer tooling, or accidental inclusion in archives, and this is especially concerning in a skill that should not manage credentials at all.
"""
申请新的 API 密钥。
"""
# 检查是否已存在 .env 文件和 API key
env_file = UPKUAJING_ENV_FILE
if env_file.exists():
Opening and reading the .env file directly processes locally stored credentials in plaintext. This expands secret exposure surface and normalizes credential handling inside a non-admin skill, making accidental disclosure or misuse more likely if the environment file is accessible to other processes or users.
env_file = UPKUAJING_ENV_FILE
if env_file.exists():
# 读取现有的 .env 文件
try:
with open(env_file, 'r', encoding='utf-8') as f:
content = f.read()
The script writes a newly issued API key into a .env file, persisting a sensitive credential in plaintext on disk. Plaintext secret storage materially increases the likelihood of credential compromise via filesystem access, backups, logs, sync tools, or accidental sharing, and is particularly unjustified given the skill's unrelated analytics purpose.
"envFilePath": str(env_file)
}
# 保存到 .env 文件
try:
with open(env_file, 'w', encoding='utf-8') as f:
f.write(f"{API_KEY_ENV}={api_key}\n")
The script can create recharge/payment orders via /agent/auth/pay/url, a financial capability with no clear relationship to HS-code statistics analysis. Exposing payment initiation inside an analytics skill creates risk of unauthorized charges, social-engineering abuse, or covert monetization paths if the skill is triggered by an agent or user who expects read-only analysis behavior.
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
API_BASE_URL = "https://openapi.upkuajing.com"
API_KEY_ENV = "UPKUAJING_API_KEY"
UPKUAJING_DIR = Path.home() / '.upkuajing'
UPKUAJING_ENV_FILE = UPKUAJING_DIR / '.env'
UPKUAJING_LOGS_DIR = UPKUAJING_DIR / 'logs'
# 日志开关
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
def load_env_file() -> Dict[str, str]:
"""
从 ~/.upkuajing/.env 文件加载环境变量。
Returns:
环境变量字典
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
def load_env_file() -> Dict[str, str]:
"""
从 ~/.upkuajing/.env 文件加载环境变量。
Returns:
环境变量字典
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
def load_env_file() -> Dict[str, str]:
"""
从 ~/.upkuajing/.env 文件加载环境变量。
Returns:
环境变量字典
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
def load_env_file() -> Dict[str, str]:
"""
从 ~/.upkuajing/.env 文件加载环境变量。
Returns:
环境变量字典
The manifest describes a skill for querying and analyzing company customs trade statistics by HS code, but this file implements exception telemetry that reports runtime errors to a platform endpoint. That behavior is operational/infrastructure reporting rather than trade-statistics analysis, so it materially exceeds the user-facing purpose described in the manifest.
The skill advertises executable behaviors that access environment variables, read/write files under the user's home directory, and make network calls, but it does not declare any explicit tool scope or permissions boundaries. In an agent environment, that lack of scoping increases the risk of over-privileged execution and makes it harder to enforce least privilege or review what the skill is allowed to do.
The document explicitly instructs agents to send request parameters, response payloads, and error context to an error-reporting endpoint, with only a brief note that sensitive fields will be automatically masked. That creates a real privacy and data-handling risk because stack traces, request bodies, and response data commonly contain personal, commercial, or credential-adjacent information, and the document does not require minimization, user disclosure, or explicit restrictions on what may be uploaded.
This file presents its purpose and CLI interaction entirely in Chinese, including the module docstring and later user-facing help/messages. Under the language/locale policy rule, forcing a specific language without user opt-in is a natural-language policy violation unless the locale restriction is clearly documented and justified.
The code can request a new API key and persist it locally to a .env file, which exceeds the expected behavior of an HS-code analytics skill. Credential minting and storage are sensitive operations; embedding them here increases the chance of silent credential proliferation, misuse by downstream components, and exposure of secrets through local file access or backups.
The auth=False/require_auth=False setting represents an unsafe default for a sensitive operation: creating API credentials. Sensitive account operations should default to authenticated, least-privilege access; relaxing that control in an unrelated skill increases the chance of unauthorized provisioning and operational abuse.
pass # 如果读取失败,继续执行
# 不需要认证申请新密钥
response = make_request('/agent/auth/create', {}, require_auth=False)
# 检查是否申请成功
if response.get('code') != 0:
The auth=False/require_auth=False setting represents an unsafe default for a sensitive operation: creating API credentials. Sensitive account operations should default to authenticated, least-privilege access; relaxing that control in an unrelated skill increases the chance of unauthorized provisioning and operational abuse.
pass # 如果读取失败,继续执行
# 不需要认证申请新密钥
response = make_request('/agent/auth/create', {}, require_auth=False)
# 检查是否申请成功
if response.get('code') != 0:
The file’s natural-language documentation and user-facing messages are entirely in Chinese, beginning with the module description on L002 and continuing throughout prints/docstrings, with no indication that the skill is region-specific or that users can opt into another language. Under the policy, forcing a specific language without opt-in is a natural-language policy violation.
This code file contains natural-language strings in Chinese in the module docstring, argument description, and error/help text, which effectively forces a specific language for users. Under the policy, locale or language constraints should either be optional for the user or clearly documented as justified for a region-specific tool.