T09 · Insecure Skill Coding Practices
- Location
src/openclaw_trading_suite/autonomy/policy.py:36- Finding
Malformed numeric values can bypass trade execution safety gates
- Content
View full analysis
float: threshold = inp.strategy_risk_limit_pct if inp.agent_risk_threshold_pct is not None: threshold = min(threshold, inp.agent_risk_threshold_pct) if inp.user_risk_threshold_pct is not None: threshold = min(threshold, inp.user_risk_threshold_pct) return threshold ``` ```python def evaluate_decision(inp: DecisionInput) -> DecisionOutcome: threshold = _effective_threshold(inp) if inp.safety_halt: return DecisionOutcome( decision=Decision.BLOCK, reason="safety_halt_enabled", effective_risk_threshold_pct=threshold, ) if inp.portfolio_drawdown_pct > inp.max_portfolio_drawdown_pct: return DecisionOutcome( decision=Decision.BLOCK, reason="portfolio_drawdown_limit_breached", effective_risk_threshold_pct=threshold, ) if inp.autonomy_level == AutonomyLevel.CAUTIOUS: return DecisionOutcome( decision=Decision.REQUIRE_APPROVAL, reason="cautious_mode_requires_confirmation", effective_risk_threshold_pct=threshold, ) if inp.autonomy_level == AutonomyLevel.BALANCED: if inp.estimated_risk_pct > threshold: return DecisionOutcome( decision=Decision.REQUIRE_APPROVAL, reason="balanced_mode_risk_threshold_exceeded", effective_risk_threshold_pct=threshold, ) return DecisionOutcome( decision=Decision.APPROVE, reason="balanced_mode_within_threshold", effective_risk_threshold_pct=threshold, ...[truncated 3426 chars]- Remediation
View remediation
bool: return isfinite(value) and 0.0 <= value <= 1.0 def evaluate_decision(inp: DecisionInput) -> DecisionOutcome: numeric_values = ( inp.estimated_risk_pct, inp.strategy_risk_limit_pct, inp.portfolio_drawdown_pct, inp.max_portfolio_drawdown_pct, ) if not all(_valid_percentage(value) for value in numeric_values): return DecisionOutcome( decision=Decision.BLOCK, reason="invalid_risk_input", effective_risk_threshold_pct=0.0, ) # Continue with policy evaluation. ``` 3. Add a separate order-validation function immediately before adapter invocation. Allow-list supported sides and order types and enforce the relationship between order type and limit price. 4. Repeat essential validation inside each real execution adapter as defense in depth. 5. Add tests covering `NaN`, positive and negative infinity, negative values, zero quantity, unsupported sides, unsupported order types, and invalid limit prices. ]]>
