T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:45- Finding
API Key Persisted in Plaintext Without Enforced Restrictive Permissions
- 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 ``` ### Technical Analysis The function persists the user-supplied API key as plaintext in `.env` within the current working directory. It uses `Path.write_text()` without explicitly enforcing restrictive file permissions. The resulting permissions therefore depend on the existing file mode or process umask. The implementation also does not verify whether `.env` is a symbolic link, does not ensure that the file is excluded from version control, and stores the key in a location that may be scanned, synchronized, backed up, or committed with the project. Although plaintext environment files are common during development, automatically persisting a credential without file-permission hardening creates an avoidable disclosure risk. ### Attack Path 1. The Skill asks the user to provide an API key. 2. The agent calls `scripts.config.set_api_key()`. 3. `save_api_key_to_env()` writes the key as `XBY_APIKEY=` into `.env`. 4. If the workspace permissions, process umask, existing file mode, backup tooling, or source-control practices are insecu ...[truncated 842 chars]- Remediation
View remediation
