T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:43- Finding
API Key Persisted in a Plaintext Environment File Without Permission Hardening
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:43-62
Vulnerability Type: Plaintext sensitive-data storage
Risk Level: MediumThe mandatory workflow in
SKILL.md:14-17instructs the agent to request an API key and pass it toscripts.config.set_api_key(). That function persists the credential in a plaintext.envfile.python def save_api_key_to_env(api_key: str) -> bool: """Store the API key in the .env file.""" 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"Failed to save API key: {e}") return FalseTechnical Analysis
Path.write_text()stores the API key unencrypted and does not explicitly enforce owner-only permissions. When the file already exists, its existing permissions are retained. When it is newly created, access permissions depend on the process umask.This persistence exceeds the minimum privilege necessary to make an authenticated API request: the key could remain in memory for the current process or be supplied through a managed secret store instead. The implementation also does not verify whether
.envis excluded from version control, protected from backups, or inaccessible to other local users and processes.The key is subsequently transmitted as the
XBY-APIKEYheader to `https://mcp.xiaobenyang.com/ ...[truncated 1185 chars]- Remediation
View remediation
Remediation Suggestions
- Prefer a platform-managed secret store, operating-system credential manager, or session-scoped environment variable instead of persistent plaintext storage.
- Do not persist the key unless the user explicitly opts in.
- If file persistence is unavoidable, create the file atomically with owner-only permissions such as
0600. - Verify and repair the permissions of an existing
.envbefore reading or updating it. - Store secrets outside the project working tree and ensure
.envis excluded from version control, logs, diagnostics, and backups where practical. - Document that the credential is sent to
mcp.xiaobenyang.com, including the purpose, destination, retention expectations, and revocation procedure. - Provide a function that removes the stored key and clears it from the process environment when no longer needed.
