T09 · Insecure Skill Coding Practices
- Location
handler.py:171- Finding
Declared allergens are not removed from generated meal plans
- Content
View full analysis
List[Dict]: """Filter out recipes containing allergens.""" if not allergies: return recipes safe_recipes = [] for recipe in recipes: all_ingredients = recipe.get("ingredients", []) has_allergen = False for allergen in allergies: if any(allergen in ing for ing in all_ingredients): has_allergen = True break if not has_allergen: safe_recipes.append(recipe) return safe_recipes ``` However, the handler generates the complete weekly plan before checking for allergens. The check only creates warnings and does not remove or replace unsafe meals: ```python meal_generator = MealPlanGenerator( request.preferences, request.constraints, request.goals ) weekly_plan = meal_generator.generate_weekly_plan() allergen_warnings = [] for day_plan in weekly_plan: for meal_type, meal in day_plan["meals"].items(): found = AllergyChecker.check_ingredients( meal.get("ingredients", []), list(all_allergies) ) if found: allergen_warnings.append( f"{day_plan['day']}{meal_type}: allergen detected: {', '.join(found)}" ) ``` The final line in this excerpt is an English rendering of the source message text; the ...[truncated 2656 chars]- Remediation
View remediation
