T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/polymarket.py:146
- Finding
- Fabricated Momentum Data Can Trigger Live Financial Trades<![CDATA[ ## Vulnerability Details **File Location**: `scripts/polymarket.py:146-170`, `scripts/polymarket.py:256-267` **Vulnerability Type**: Fail-open trading logic using fabricated market data **Risk Level**: High ### Vulnerable Code ```python def calculate_momentum(market_id): # Fetch price history from CLOB API try: # Get candles (15m resolution = 900 seconds) end = int(time.time()) start = end - (900 * 5) path = f"/prices/history?market={market_id}&interval=15m&start={start}&end={end}" headers = get_api_headers("GET", path) res = requests.get(f"{CLOB_API}{path}", headers=headers) if res.status_code == 200: prices = res.json() if len(prices) >= 3: p_now = float(prices[-1].get('price', 0)) p_old = float(prices[-3].get('price', 0)) if p_old > 0: momentum = (p_now - p_old) / p_old log_event("DEBUG", "STRATEGY", f"Market {market_id}: Price now {p_now}, 3p ago {p_old}, Mom {momentum:.4f}") return momentum # DEMO FALLBACK: If real data isn't available for this market, we mock a 3% gain # to show the user the order logic triggering. log_event("DEBUG", "DEMO", f"Mocking 3% momentum for demo: Market {market_id}") return 0.03 except Exception as e: log_event("ERROR", "STRATEGY", f"Momentum calc failed: {str(e)}") return 0.0 ``` ```python def execute_scan(): log_event("INFO", "SCAN", "Starting momentum scan loop...") markets = scan_markets() for market in markets: m_id = market.get('id') mom = calculate_momentum(m_id) if mom > 0.02: place_order(m_id, "YES") elif mom < -0.02: place_order(m_id, "NO") log_event("INFO", "SCAN", f"Scan finished. Analyzed {len(markets)} markets.") ``` ### Technical Analysis When the price-history API does not prov ...[truncated 2152 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the fabricated `0.03` fallback from all production paths. 2. Fail closed by returning `None` when market data is unavailable, incomplete, stale, malformed, or inconsistent. 3. Permit mock signals only behind an explicit simulation-only control that cannot coexist with live execution. 4. Before trading, validate: - Minimum candle count. - Candle timestamps and ordering. - Price range and numeric type. - Market and token identity. - Data freshness. 5. Require multiple independent checks before order submission, including order-book liquidity and maximum slippage. 6. Add per-order, per-scan, and daily spending limits. 7. Add tests proving that missing, empty, malformed, and stale market data can never invoke `place_order()` in live mode. 8. Consider requiring explicit operator confirmation when transitioning from simulation to live execution. ]]>
