T09 · Insecure Skill Coding Practices
- Location
scripts/paper_trading.py:222- Finding
Path Traversal Through Unvalidated Account Identifiers
- Content
View full analysis
Optional[Account]: """Load account from file.""" account_file = self.accounts_dir / f"{account_id}.json" if not account_file.exists(): return None data = json.loads(account_file.read_text()) ``` ### Technical Analysis The account identifier supplied through the `--account` CLI option is used directly to construct a filesystem path. The application neither restricts the identifier to the generated 12-character hexadecimal format nor verifies that the resolved path remains inside `self.accounts_dir`. Because `pathlib.Path` does not remove traversal components when joining paths, an identifier such as `../../target` causes the application to access a path equivalent to: ```text ~/.polymarket-paper/accounts/../../target.json ``` The loader consequently permits reading a JSON file outside the intended account directory if that file exists and follows the expected account schema. The write path creates an additional hazard. `_load_account()` accepts the `account_id` stored inside the loaded JSON file, and mutating operations later pass the resulting object to `_save_account()`. A crafted account document can therefore place traversal components in its internal `account_id` field and direct the subsequent write outside the account directory. ### Attack Path 1. An attacker creates or identifies a JSON file accessibl ...[truncated 1528 chars]- Remediation
View remediation
