T09 · Insecure Skill Coding Practices
- Location
scripts/calculate_promotion.py:32- Finding
Promotion applicability and exclusion rules are not enforced
- Content
View full analysis
bool: applicable_to = promo.get("applicable_to", []) excluded = promo.get("excluded", []) # Check exclusions first for ex in excluded: if ex in (item_sku, item_category, "全场"): return False # Check inclusions if not applicable_to or "全场" in applicable_to: return True return item_sku in applicable_to or item_category in applicable_to ``` However, the promotion-processing loops never invoke this function and instead calculate every active supported promotion against the entire cart subtotal: ```python # Apply stackable promos first for promo in stackable_promos: ptype = promo.get("type", "") if ptype == "threshold": discount, desc = apply_threshold(promo, subtotal) elif ptype == "discount": discount, desc = apply_discount(promo, subtotal) else: continue if discount > 0: applied_promos.append({"promo": promo.get("title"), "rule": desc, "discount": discount}) total_discount += discount # For non-stackable promos, pick the best one best_nonstackable = None best_discount = 0.0 best_desc = "" for promo in nonstackable_promos: ptype = promo.get("type", "") if ptype == "threshold": discount, desc = apply_threshold(promo, subtotal) elif ptype == "discount": discount, desc = apply_discount(promo, subtotal) else: continue if discount > best_discount: best_discount = discount best_nonstackable = promo best_desc = desc ``` ### Technical Analysis Promotions can contain `applicable_to` and `excluded` restrict ...[truncated 1885 chars]- Remediation
View remediation
