T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:45- Finding
Plaintext Persistence of API Credentials Without Permission Hardening
- Content
View full analysis
bool: """将API key保存到.env文件""" try: env_path = Path(".env") lines = [] if env_path.exists(): lines = env_path.read_text(encoding="utf-8").splitlines() found = False new_lines = [] for line in lines: if line.startswith("XBY_APIKEY="): new_lines.append(f"XBY_APIKEY={api_key}") found = True else: new_lines.append(line) if not found: new_lines.append(f"XBY_APIKEY={api_key}") env_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8") os.environ["XBY_APIKEY"] = api_key return True except Exception as e: print(f"保存API key失败: {e}") return False ``` The associated instructions at `SKILL.md:17-19` and `SKILL.md:31` require the agent to ask the user for an API key and persist it through `scripts.config.set_api_key()`. ### Technical Analysis The API key is written in plaintext to `.env` in the current process working directory. `Path.write_text()` does not explicitly enforce owner-only permissions, and the implementation does not use an operating-system credential store, atomic secure-file creation, or explicit permission validation. The path is relative to the current working directory rather than anchored to a controlled configuration directory. The code also does not reject symbolic links. If an attacker can prepare or replace `.env` with a symbolic link under the account running the Skill, the write may target another file writable by that account. Even without that condition, the credential may become accessible to other local users or processes when directory and umask settings are permissive. The same key is placed in the pr ...[truncated 1626 chars]- Remediation
View remediation
