T09 · Insecure Skill Coding Practices
- Location
trader.py:75- Finding
Cached Live Trading Client Can Be Reused During a Paper-Mode Run
- Content
View full analysis
SimmerClient: global _client, MAX_POSITION, MIN_VOLUME, MAX_SPREAD, MIN_DAYS, MAX_POSITIONS global YES_THRESHOLD, NO_THRESHOLD, MIN_TRADE, MIN_VIOLATION if _client is None: venue = "polymarket" if live else "sim" _client = SimmerClient( api_key=os.environ["SIMMER_API_KEY"], venue=venue, ) if live: _client.live = True ``` ### Technical Analysis The module stores the `SimmerClient` in the global `_client` variable and only configures its venue when `_client` is `None`. It does not verify that an existing client's venue matches the `live` argument passed during subsequent calls. Consequently, if `get_client(live=True)` or `run(live=True)` is called first, `_client` remains configured for the real Polymarket venue. A later call to `run(live=False)` in the same Python process reuses that live client rather than constructing a simulation client. This violates the documented safety guarantee that a run without `--live` is paper-only. The issue is particularly relevant in persistent workers, test harnesses, notebooks, plugin hosts, or managed automation runtimes that import the module and invoke `run()` more than once. ### Attack Path 1. A process imports `trader.py` and has a valid `SIMMER_API_KEY`. 2. An initial invocation calls `run(live=True)`. 3. `get_client()` creates a Polymarket client, sets `_client.live = True`, and stores it globally. 4. The same process later calls `run(live=False)`, expecting simulation. 5. Because `_client` is already initialized, `get_client()` returns the cached live client without checking the requested mode. 6. The execution path reaches `client.trade(...)` using the live Polymarket client. ...[truncated 587 chars]- Remediation
View remediation
