T09 · Insecure Skill Coding Practices
Note
- Location
SKILL.md:207- Finding
Division by Zero in Accounts Receivable Aging Analysis
- Content
View full analysis
dict: """ Analyze AR aging and identify collection risk. Args: aging_buckets: {"0_30": x, "31_60": x, "61_90": x, "90_plus": x} total_ar: Total AR balance (validation check) Returns: Risk assessment and recommended actions """ at_risk = aging_buckets.get("61_90", 0) + aging_buckets.get("90_plus", 0) at_risk_pct = at_risk / total_ar if total_ar else 0 recommendations = [] if aging_buckets.get("31_60", 0) / total_ar > 0.3: recommendations.append({ "action": "Send reminder notices to 31-60 day balances", "priority": "medium", "cash_impact": aging_buckets["31_60"], "timeline": "within 1 week" }) if aging_buckets.get("61_90", 0) > 0: recommendations.append({ "action": "Direct phone outreach to 61-90 day accounts", "priority": "high", "cash_impact": aging_buckets["61_90"], "timeline": "this week" }) if aging_buckets.get("90_plus", 0) > 0: recommendations.append({ "action": "Place 90+ day accounts on collections / payment plan", "priority": "critical", "cash_impact": aging_buckets["90_plus"], "timeline": "immediately" }) return { "at_risk_usd": at_risk, "at_risk_pct": round(at_risk_pct * 100, 1), "collectible_estimate_usd": at_risk * 0.75, "risk_level": "critical" if at_risk_pct > 0.20 else "moderate" if at_risk_pct > 0.10 else "low", "recommendations": recommendations } ``` ### Technical Analysis The function conditionally guards the first division ...[truncated 1844 chars]- Remediation
View remediation
dict: required_buckets = ("0_30", "31_60", "61_90", "90_plus") if not isinstance(total_ar, (int, float)): raise TypeError("total_ar must be numeric") if total_ar < 0: raise ValueError("total_ar cannot be negative") normalized = {} for bucket in required_buckets: value = aging_buckets.get(bucket, 0) if not isinstance(value, (int, float)): raise TypeError(f"{bucket} must be numeric") if value < 0: raise ValueError(f"{bucket} cannot be negative") normalized[bucket] = value bucket_total = sum(normalized.values()) if abs(bucket_total - total_ar) > 0.01: raise ValueError("AR aging buckets do not reconcile to total_ar") def ratio(value: float) -> float: return value / total_ar if total_ar > 0 else 0.0 at_risk = normalized["61_90"] + normalized["90_plus"] at_risk_pct = ratio(at_risk) recommendations = [] if ratio(normalized["31_60"]) > 0.3: recommendations.append({ "action": "Send reminder notices to 31-60 day balances", "priority": "medium", "cash_impact": normalized["31_60"], "timeline": "within 1 week" }) # Continue using normalized values for the remaining analysis. ``` If a zero `total ...[truncated 159 chars]
