T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:46- Finding
API Key Persisted in a Plaintext File Without 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 except Exception as e: ``` ### Technical Analysis The Skill requires the user to provide an API key and persistently stores that credential in a predictable `.env` file. `Path.write_text()` creates or replaces the file using permissions determined by the process umask. The implementation does not explicitly restrict the file to the owning user, verify that the destination is a regular file, reject symbolic links, or obtain separate consent for persistent credential storage. The corresponding instructions in `SKILL.md:18-19` and `SKILL.md:34` require the Agent to collect and save the key. The credential is subsequently sent in the `XBY-APIKEY` request header to `https://mcp.xiaobenyang.com/api`. Sending the key to that fixed HTTPS endpoint is part of the declared provider-mediated service design, but persistent plaintext storage is not the minimum privilege necessary to perform an individual search. Exploitation requires local access to the project directory, access through another process running under a sufficiently privileged account, ...[truncated 1238 chars]- Remediation
View remediation
