T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:34
- Finding
- Mailbox credentials may be exposed through chat, command-line arguments, environment variables, and persistent global configuration<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:34-63`, `SKILL.md:89-93`, `scripts/email_reader.py:42-72`, `scripts/email_reader.py:237-243` **Vulnerability Type**: Insecure credential handling **Risk Level**: High ### Vulnerable Code and Instructions ```markdown python3 scripts/email_reader.py \ --user your@163.com \ --pass_ YOUR_AUTH_CODE \ --server pop.163.com \ --port 995 \ subjects --n 5 ``` ```markdown export EMAIL_USER="your@163.com" export EMAIL_PASS="YOUR_AUTH_CODE" export POP3_SERVER="pop.163.com" export POP3_PORT="995" python3 scripts/email_reader.py subjects --n 5 ``` ```markdown 在 OpenClaw 中,可通过 `gateway config.patch` 将环境变量写入全局配置: { "env": { "EMAIL_USER": "your@163.com", "EMAIL_PASS": "YOUR_AUTH_CODE", "POP3_SERVER": "pop.163.com", "POP3_PORT": "995" } } ``` ```markdown ## 工作流程 1. 先询问用户的邮箱账号、授权码(密码)、邮箱类型 2. 根据邮箱类型查 `references/providers.md` 确认服务器地址 3. 决定配置方式(推荐环境变量),完成配置 4. 运行脚本,解析 JSON 输出后以自然语言回复用户 ``` ```python def load_config(args): """从 CLI / 环境变量 / .email_config 三层加载配置,返回 dict""" cfg = { "user": None, "pass_": None, "server": None, "port": 995, } # 层 3:.email_config 文件 config_file = Path(__file__).parent / ".email_config" if config_file.exists(): parser = configparser.ConfigParser() parser.read(config_file) if "email" in parser: s = parser["email"] cfg["user"] = s.get("user", cfg["user"]) cfg["pass_"] = s.get("pass_", cfg["pass_"]) cfg["server"] = s.get("server", cfg["server"]) cfg["port"] = int(s.get("port", cfg["port"])) # 层 2:环境变量 cfg["user"] = os.environ.get("EMAIL_USER", cfg["user"]) cfg["pass_"] = os.environ.get("EMAIL_PASS", cfg["pass_"]) cfg["server"] = os.environ.get("POP3_SERVER", cfg["server"]) cfg["port"] = int(os.environ.get("POP3_PORT", cfg["port"])) # 层 1:命令行参数(最高优先级) if args.user: cfg["us ...[truncated 3125 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not instruct the Agent to request mailbox passwords or authorization codes in ordinary chat. 2. Integrate with a dedicated secret manager or masked credential-input mechanism that does not place secrets in model context or transcripts. 3. Remove or deprecate the `--pass_` argument. Read the credential from a protected file descriptor, operating-system keychain, or narrowly scoped secret injection mechanism. 4. Do not write mailbox credentials into global Agent configuration. Scope secret injection to the single email-reader process and remove it immediately afterward. 5. If environment variables remain supported, prevent unnecessary child-process inheritance and document that they are a compatibility fallback rather than the preferred mechanism. 6. If `.email_config` remains supported, verify ownership and reject the file unless permissions prevent access by group and other users. Avoid following symlinks where practical. 7. Ensure logs and error handlers redact account identifiers, authorization codes, connection strings, and configuration values. 8. Prefer provider-specific OAuth or revocable, narrowly scoped application credentials where POP3 provider support permits it. 9. Document credential revocation and rotation procedures so users can rapidly invalidate a potentially exposed authorization code. ]]>
