T09 · Insecure Skill Coding Practices
- Location
scripts/pricing.py:90- Finding
Missing Validation Allows Negative Pricing Quotes
- Content
View full analysis
PricingResult: """计算最终定价""" if gpu not in BASE_PRICES: raise ValueError(f"不支持的GPU型号: {gpu},支持的型号: {list(BASE_PRICES.keys())}") base_price_per_hr = BASE_PRICES[gpu] base_monthly = base_price_per_hr * count * 730 # ~730小时/月 base_yearly = base_monthly * 12 q_discount = get_quantity_discount(count) d_discount = get_duration_discount(duration_months) p_discount = get_prepay_discount(prepay_cycle) # 累乘折扣 (1 - d1) * (1 - d2) * (1 - d3) combined = 1.0 - (1.0 - q_discount) * (1.0 - d_discount) * (1.0 - p_discount) discounted_monthly = base_monthly * (1.0 - combined) discounted_yearly = discounted_monthly * 12 return PricingResult( gpu=gpu, base_price_per_hr=base_price_per_hr, gpu_count=count, duration_months=duration_months, prepay_cycle=prepay_cycle, base_monthly=base_monthly, base_yearly=base_yearly, quantity_discount=q_discount, duration_discount=d_discount, prepay_discount=p_discount, combined_discount=combined, discounted_monthly=discounted_monthly, discounted_yearly=discounted_yearly, monthly_savings=base_monthly - discounted_monthly, yearly_savings=base_yearly - discounted_yearly, price_per_gpu_hr=base_price_per_hr * (1.0 - combined), ) ``` The same unvalidated values reach this function from the command-line path: ```python result = calculate_pricing(args.gpu, args.count, args.duration, args.prepay) ``` The comparison path also parses signed integers without validating their permitted ranges: ```python try: count = int(parts[matched_n]) duration = int(parts[mat ...[truncated 2634 chars]- Remediation
View remediation
