T09 · Insecure Skill Coding Practices
- Location
trader.py:297- Finding
Market Safety Checks Fail Open When Context Retrieval Fails
- Content
View full analysis
Vulnerability Details
File Location:
trader.py:297-313
Vulnerability Type: Fail-open validation of live trading safeguards
Risk Level: HighVulnerable code:
python def get_market_context(market_id: str, my_probability: float = None) -> dict: """Get market context with safeguards and edge analysis.""" try: if my_probability is not None: return get_client()._request( "GET", f"/api/sdk/context/{market_id}", params={"my_probability": my_probability} ) return get_client().get_market_context(market_id) except Exception: return None def check_safeguards(context: dict) -> tuple[bool, list[str]]: """Check context for safeguards. Returns (should_trade, reasons).""" if not context: return True, []Technical Analysis
get_market_context()suppresses every exception and returnsNone. The downstreamcheck_safeguards()function interprets a missing or empty context as authorization to proceed.This is a fail-open security design. The unavailable context can contain the information needed to enforce resolution status, flip-flop warnings, time-to-resolution limits, liquidity requirements, and slippage limits. A network failure, authentication error, malformed SDK response, rate limit, or service disruption therefore disables all of these controls rather than stopping the transaction.
Because the same path is used before entry and exit orders, the issue can affect both purchases and sales in live mode.
Attack Path
- The Skill is started with
--live. - An F1 market meets the static model's entry or exit threshold.
- Context retrieval fails because of a service outage, rate limit, malformed response, network interference, or other SDK exception.
get_market_context()catches the exception and returnsNone.check_safeguards(None)returns(True, []). ...[truncated 901 chars]
- The Skill is started with
- Remediation
View remediation
Remediation Suggestions
- Fail closed whenever market context cannot be retrieved:
python def check_safeguards(context: dict) -> tuple[bool, list[str]]: if not context: return False, ["Market context unavailable"] - Preserve and log a sanitized error reason rather than silently swallowing every exception.
- Validate the context response schema and reject responses missing required
market,warnings,discipline, orslippageinformation. - Use narrowly scoped exception handling for expected network and SDK errors.
- Permit an explicit fail-open mode only for dry-run analysis, never for live execution.
- Add tests proving that timeouts, HTTP errors, malformed responses, and empty contexts prevent live orders.
- Fail closed whenever market context cannot be retrieved:
