T09 · Insecure Skill Coding Practices
- Location
scripts/budget.py:261- Finding
Unvalidated Numeric Inputs Permit Budget Enforcement Bypass
- Content
View full analysis
- Remediation
View remediation
float: if not math.isfinite(value) or value <= 0: raise ValueError(f"{field} must be finite and greater than zero") return value ``` 2. Require token counts to be non-negative integers: ```python def validate_token_count(value: int, field: str) -> int: if isinstance(value, bool) or not isinstance(value, int) or value < 0: raise ValueError(f"{field} must be a non-negative integer") return value ``` 3. Apply validation inside `BudgetConfig.set_global_limit()`, `BudgetConfig.set_agent_limit()`, `PricingTable.update_model()`, `PricingTable.get_cost()`, and `UsageTracker.log_usage()`. Library-level validation is necessary because these classes may be called without the CLI. 4. Verify that every calculated and supplied cost is finite and non-negative before persisting it. 5. Treat malformed or non-finite values in existing configuration and ledger records as errors rather than silently using them in calculations. Consider failing closed for budget checks when accounting data cannot be validated. 6. Serialize standards-compliant JSON by using `json.dump(..., allow_nan=False)` and `json.dumps(..., allow_nan=False)`. 7. Add regression tests covering negative token counts, negative limits and prices, zero or non-finite limits, `NaN`, positive and negative infinity, malformed ledger records, and direct library invocation. ]]>
