T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/trading212_skill.py:30
- Finding
- Shared Parent Environment File Can Redirect Operations to Live Trading<![CDATA[ ## Vulnerability Details **File Location**: `scripts/trading212_skill.py:30-34` **Vulnerability Type**: Unsafe configuration loading from a shared parent directory **Risk Level**: High ### Vulnerable Code ```python # Load .env from project root before any Trading212 imports. _env_path = Path(__file__).resolve().parents[3] / ".env" if _env_path.exists(): from dotenv import load_dotenv load_dotenv(_env_path) ``` ### Technical Analysis The code claims to load `.env` from the project root, but `Path(__file__).resolve().parents[3]` resolves to `/tmp` in the audited directory layout. Consequently, the Skill implicitly trusts `/tmp/.env`, a file outside the project and potentially shared with unrelated users or processes. `load_dotenv()` does not override variables already present by default, but it supplies variables that are absent from the process environment. This includes `TRADING212_DEMO`, which controls whether the client connects to the demo or live Trading212 API. The behavior exceeds the minimum privilege and trust boundary required for the Skill. Configuration should come from the Skill directory or explicitly supplied environment variables, not a shared parent directory. ### Attack Path 1. An attacker with local write access creates `/tmp/.env`. 2. The file includes: ```text TRADING212_DEMO=false ``` 3. A user or agent starts the Skill without explicitly setting `TRADING212_DEMO`. 4. The Skill loads the attacker-controlled `/tmp/.env`. 5. `Trading212Client` interprets the value as live-trading mode. 6. A subsequent `execute_trade` invocation submits an order to the live Trading212 endpoint. Exploitation still requires valid Trading212 credentials to be available, but the attacker-controlled file can silently change the environment selected for those credentials. ### Impact Assessment The flaw can redirect operations from paper trading to real-money trading. In combination with the unguarded execution interface, this can ...[truncated 169 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Resolve the file relative to the actual Skill root: ```python _PROJECT_ROOT = Path(__file__).resolve().parents[1] _env_path = _PROJECT_ROOT / ".env" ``` - Prefer requiring deployment-time environment variables instead of implicitly loading a file. - If `.env` support is retained: - Verify that the resolved path remains under the project root. - Reject symlinks. - Verify file ownership and require restrictive permissions. - Log the selected environment without disclosing credentials. - Require a separate explicit command-line switch for live trading; do not permit `.env` alone to activate it. - Fail closed unless demo mode is positively established. ]]>
