T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/get_rates.py:102
- Finding
- Fabricated Financial Rates Returned After Data Retrieval Failures## Vulnerability Details **File Location**: `scripts/get_rates.py`, lines 102–132 **Vulnerability Type**: Unsafe fallback behavior and silent fabrication of financial data **Risk Level**: High ### Vulnerable Code ```python try: bcv_rate_str, date_text, source, date_ok = fetch_bcv() except Exception: try: source = "exchange fallback" bcv_rate_str = fetch_fallback_rate() except Exception: source = "valor de respaldo" bcv_rate_str = "420" print("⚠️ Usando valor de respaldo") bcv_rate = float(bcv_rate_str) print(f"✅ Tasa BCV: {bcv_rate_str} Bs/USD") print(f"🔎 Fuente BCV: {source.replace('https://www.', '').replace('https://', '').rstrip('/')}") if date_text: print(f"📅 Fecha valor BCV: {date_text}") if not date_ok: print("⚠️ Advertencia: la fecha valor BCV no coincide con hoy/mañana") print() print("📊 Consultando USDT Binance P2P...") try: buy_avg, buy_min, buy_max, buy_count = fetch_binance_side("SELL") except Exception: buy_avg = bcv_rate * 1.45 buy_min = bcv_rate * 1.42 buy_max = bcv_rate * 1.48 buy_count = "0 (estimado)" try: sell_avg, sell_min, sell_max, sell_count = fetch_binance_side("BUY") except Exception: sell_avg = bcv_rate * 1.46 sell_min = bcv_rate * 1.43 sell_max = bcv_rate * 1.49 sell_count = "0 (estimado)" ``` ### Technical Analysis The implementation catches every exception raised while retrieving or parsing BCV and Binance data. These broad handlers cover network timeouts, TLS failures, malformed JSON, upstream schema changes, HTML parsing failures, service errors, and programming defects. If both BCV sources fail, the application substitutes a hardcoded exchange rate of `420`. If either Binance request fails, it manufactures P2P prices by multiplying the BCV value by fixed factors. The program then uses these synthetic values to calculate and displa ...[truncated 2484 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the hardcoded BCV rate and all multiplier-based Binance estimates. Financial rates should never be fabricated when authoritative sources are unavailable. 2. Fail closed when live data cannot be obtained. Print a clear error message, omit dependent calculations, and return a nonzero exit status. 3. Catch specific exceptions such as `urllib.error.URLError`, `TimeoutError`, `json.JSONDecodeError`, `KeyError`, and `ValueError` instead of suppressing every `Exception`. 4. Preserve and report the reason each source failed without exposing sensitive implementation details. 5. Represent source status explicitly in machine-readable output, using fields such as `source`, `retrieved_at`, `is_live`, and `error`. 6. If cached data is supported, label it prominently with its original retrieval timestamp and enforce a documented maximum age. 7. Do not calculate gaps or conversions unless both required rates were retrieved successfully and validated as positive, finite numeric values. 8. Update `SKILL.md` to document every fallback behavior and clearly state that unavailable sources produce an error rather than estimated market data. 9. Add tests covering total source failure, malformed HTML, malformed JSON, empty Binance offers, zero or negative rates, and partial-source availability.
