T09 · Insecure Skill Coding Practices
Error
- Location
- news_events.py:40
- Finding
- Trading Safety Checks Fail Open When Market Context Is Unavailable<![CDATA[ ## Vulnerability Details **File Location**: `news_events.py`, lines 40-59; approval is consumed at lines 449-452 **Vulnerability Type**: Fail-open financial transaction control **Risk Level**: High ### Vulnerable Code ```python def check_context(client, market_id, my_probability=None): """Check market context before trading (flip-flop, slippage, edge).""" try: params = {} if my_probability is not None: params["my_probability"] = my_probability ctx = client.get_market_context(market_id, **params) trading = ctx.get("trading", {}) flip_flop = trading.get("flip_flop_warning") if flip_flop and "SEVERE" in flip_flop: return False, f"flip-flop: {flip_flop}" slippage = ctx.get("slippage", {}) if slippage.get("slippage_pct", 0) > 0.15: return False, "slippage too high" edge = ctx.get("edge_analysis", {}) if edge.get("recommendation") == "HOLD": return False, "edge below threshold" return True, "ok" except Exception: return True, "context unavailable" ``` The returned approval is used as follows: ```python ok, reason = check_context(client, market_id) if not ok: log.warning("Skipping trade: %s", reason) continue ``` ### Technical Analysis `check_context()` is intended to enforce pre-trade safeguards covering severe flip-flop warnings, excessive slippage, and insufficient market edge. However, every exception—including network timeouts, authentication errors, SDK failures, malformed responses, and unexpected response types—is converted into an affirmative trading decision. This is a fail-open security design. The absence of validated safety information is treated as equivalent to successful validation. In live mode, execution can consequently continue to `client.trade(...)` while all contextual risk controls are unavailable. The broad `except Exception` also suppresses the underlying error and ...[truncated 1111 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Fail closed whenever market context cannot be validated: ```python except Exception as exc: log.warning("Unable to validate market context: %s", exc) return False, "context unavailable" ``` - Catch specific SDK, timeout, parsing, and authentication exceptions rather than suppressing every exception. - Apply bounded retries with exponential backoff for transient failures. - Require a complete, schema-validated context response before live trading. - Reject missing or nonnumeric slippage values rather than silently treating them as zero. - Add an explicit operator-controlled emergency override if fail-open behavior is ever required; it should not be the default. - Record failed checks in audit logs without exposing credentials or other sensitive values. ]]>
