T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/game_loop.py:20
- Finding
- Python Example Encourages Plaintext API Key Storage in Source Code## Vulnerability Details **File Location**: `scripts/game_loop.py`, lines 20–26 **Vulnerability Type**: Plaintext credential storage in source code **Risk Level**: Medium ```python KEY = "ma_your_key" # UPDATE THIS while True: # Get state state = requests.get(f"{API}/game/state", headers={"X-API-Key": KEY}).json()["data"] ``` ### Technical Analysis The example instructs users to replace a source-code placeholder with their live Moltbot Arena API key. The resulting credential is stored as a plaintext global variable and attached to authenticated requests through the `X-API-Key` header. Although the distributed value is only a placeholder and no live credential is present in the audited package, the recommended configuration pattern can cause users to commit, share, archive, or otherwise disclose a real key with the script. Source repositories, code review systems, backups, and diagnostic bundles commonly retain historical versions even after a secret is removed. ### Attack Path 1. A user replaces `ma_your_key` with a valid Moltbot Arena API key as instructed. 2. The modified script is committed to a repository, shared with another party, included in a backup, or exposed through another source-code distribution channel. 3. An attacker reads the plaintext key from the script or repository history. 4. The attacker places the key in the `X-API-Key` header and calls authenticated Arena endpoints. 5. The attacker retrieves the victim agent's game state or submits unauthorized game actions under that agent's identity. ### Impact Assessment Exposure grants the attacker the application-level privileges associated with the compromised Moltbot Arena API key. Based on the documented endpoints, this can include reading the agent's complete game state and statistics, submitting actions for controlled units and structures, and invoking respawn functionality when applicable. The demonstrated issue does not g ...[truncated 239 chars]
- Remediation
- ## Remediation Suggestions - Load the API key from an environment variable or a dedicated secret-management service instead of embedding it in source code. - Fail closed with a clear error when the secret is absent; do not silently use a placeholder. - Keep local environment files outside version control and provide a `.gitignore` rule for files such as `.env`. - Document secret rotation procedures for keys that may already have entered source-control history. - Avoid printing the key or complete authentication headers in errors and diagnostic logs. - Consider using a persistent HTTP session with authentication configured once, while ensuring headers remain redacted. Example hardened configuration: ```python import os KEY = os.environ.get("MOLTBOT_ARENA_API_KEY") if not KEY: raise RuntimeError("MOLTBOT_ARENA_API_KEY is required") ```
