T09 · Insecure Skill Coding Practices
- Location
SKILL.md:38- Finding
API Key Exposure Through Unsafe Display Instructions and Plaintext Storage
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:38-50,scripts/auth.py:18-34,scripts/auth.py:62-74
Vulnerability Type: Credential exposure and insecure secret storage
Risk Level: HighVulnerable Code
SKILL.md:38-50markdown ## API密钥与充值 使用此技能需要API密钥。API密钥保存在 `~/.upkuajing/.env` 文件中: ```bash cat ~/.upkuajing/.env文件内容示例:
text UPKUAJING_API_KEY=your_api_key_here未设置API密钥
请先检查
~/.upkuajing/.env文件是否有 UPKUAJING_API_KEY; 如果未设置 UPKUAJING_API_KEY API密钥,请提示并让用户选择:- 用户有,由用户提供(手动添加到 ~/.upkuajing/.env 文件)
- 用户没有,你可使用接口进行申请(
auth.py --new_key),申请到新密钥后,会自动保存到 ~/.upkuajing/.env
text `scripts/auth.py:18-34` ```python # 检查是否已存在 .env 文件和 API key env_file = UPKUAJING_ENV_FILE if env_file.exists(): # 读取现有的 .env 文件 try: with open(env_file, 'r', encoding='utf-8') as f: content = f.read() # 检查是否已有 API key for line in content.splitlines(): line = line.strip() if line.startswith(f'{API_KEY_ENV}='): existing_key = line.split('=', 1)[1].strip() if existing_key: return { "success": False, "message": f"错误:{env_file} 中已存在API密钥({existing_key[:10]}...)。\n如需重新申请,请先删除文件中的 {API_KEY_ENV} 后再运行此命令。", "envFilePath": str(env_file) }scripts/auth.py:62-74python # 确保 ~/.upkuajing 目录存在 try: UPKUAJING_DIR.mkdir(parents=True, exist_ok=True) except OSError as e: return { "success": False, "message": f"API密钥申请成功,但创建目录失败:{str(e)}。\n请手动创建目录 {UPKUAJING_DIR} 并设置环境变量 {API_KEY_ENV}。", "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")T
...[truncated 2431 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the instruction to print the entire
.envfile. - Replace it with a presence-only check that never renders the value, or let the Python code report only whether the key is configured.
- Create
~/.upkuajingwith owner-only permissions equivalent to0700. - Create or immediately change
.envto owner-read/write permissions equivalent to0600. - Do not include any portion of an existing key in status or error messages.
- Prefer the process environment or an operating-system credential store over a plaintext file.
- If file storage remains supported, verify that the path is a regular file owned by the current user before reading or overwriting it.
- Document credential rotation and revocation procedures for users who may have followed the previous display instruction.
- Remove the instruction to print the entire
