T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:45- Finding
API Key Persisted in a Plaintext Environment File
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:45-63
Vulnerability Type: Plaintext storage of sensitive credentials
Risk Level: MediumThe Skill instructions at
SKILL.md:17-18andSKILL.md:34direct the agent to collect an API key from the user and persist it throughscripts.config.set_api_key(). The following implementation stores that credential directly in.env: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 store API key: {e}") return FalseTechnical Analysis
The API key is written as an unencrypted string to a predictable file in the process's current working directory.
Path.write_text()uses the process's normal file-creation behavior and umask; the code does not explicitly enforce owner-only permissions, use a protected credential store, or perform an atomic secure file creation.The predictable filename also increases the likelihood that the credential will be included in source-control commits, directory archives, backups, diagnostics, or copied workspaces. The implementation additionally places the key in the process environment, where it may be accessible to other code running with sufficient local pri ...[truncated 1009 chars]
- Remediation
View remediation
Remediation Suggestions
- Prefer an operating-system credential manager, secret-management service, or session-only secret injection instead of persistent plaintext storage.
- If file persistence is unavoidable, create the credential file atomically with owner-only permissions such as
0600, and verify its ownership and permissions before reading it. - Store secrets in a dedicated credential file rather than rewriting a general-purpose
.envfile. - Add
.envand all credential-file variants to source-control ignore rules and distribution exclusions. - Warn users explicitly before persisting the credential and provide a session-only option.
- Implement credential revocation and rotation guidance for users who may have exposed an existing
.envfile. - Avoid placing the credential in the process environment unless required, and minimize its lifetime in memory.
