T09 · Insecure Skill Coding Practices
Error
- Location
- trader.py:286
- Finding
- Declared Market Safety Filters Are Not Enforced<![CDATA[ ## Vulnerability Details **File Location**: `trader.py:41-44`, `trader.py:286-310` **Vulnerability Type**: Missing enforcement of configured trading safeguards **Risk Level**: High ### Vulnerable Code ```python MAX_POSITION = float(os.environ.get("SIMMER_MAX_POSITION", "40")) MIN_VOLUME = float(os.environ.get("SIMMER_MIN_VOLUME", "1000")) MAX_SPREAD = float(os.environ.get("SIMMER_MAX_SPREAD", "0.10")) MIN_DAYS = int(os.environ.get( "SIMMER_MIN_DAYS", "0")) MAX_POSITIONS = int(os.environ.get( "SIMMER_MAX_POSITIONS", "8")) ``` ```python def run(live: bool = False) -> None: mode = "LIVE" if live else "PAPER (sim)" safe_print(f"[twitter-bin-decay] mode={mode} max_pos=${MAX_POSITION}") client = get_client(live=live) markets = find_markets(client) safe_print(f"[twitter-bin-decay] {len(markets)} post-count bin markets found") placed = 0 for m in markets: if placed >= MAX_POSITIONS: break side, size, reasoning = compute_signal(m) if not side: safe_print(f" [skip] {reasoning}") continue ok, why = context_ok(client, m.id) if not ok: safe_print(f" [skip] {why}") continue try: r = client.trade( market_id=m.id, side=side, amount=size, source=TRADE_SOURCE, skill_slug=SKILL_SLUG, reasoning=reasoning, ) tag = "(sim)" if r.simulated else "(live)" status = "OK" if r.success else f"FAIL:{r.error}" safe_print(f" [trade] {side.upper()} ${size} {tag} {status} -- {reasoning[:70]}") if r.success: placed += 1 except Exception as e: safe_print(f" [error] {m.id}: {e}") ``` ### Technical Analysis The application loads `MIN_VOLUME` and `MIN_DAYS` as security and risk-management parameters, but neither value is consulted before an order is submitted. Consequently, a ...[truncated 2059 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Before signal generation or order submission, reject markets whose reported volume is below `MIN_VOLUME`. 2. Parse and validate the authoritative market resolution timestamp, then reject markets with fewer than `MIN_DAYS` remaining. 3. Treat missing or malformed volume and resolution metadata as a failed safety check in live mode rather than permitting the trade. 4. Query current account positions through the SDK before trading. 5. Count distinct existing open positions together with orders successfully created during the current run. 6. Reject any order that would cause the portfolio to exceed `MAX_POSITIONS`. 7. Recheck market metadata immediately before submitting a live order to reduce time-of-check/time-of-use risk. 8. Add tests proving that low-volume markets, out-of-window markets, and portfolios already at the position limit cannot reach `client.trade()`. ]]>
