T09 · Insecure Skill Coding Practices
- Location
scripts/model-shot-prompt.py:52- Finding
Unbounded Prompt Count Allows Resource Exhaustion
- Content
View full analysis
1 else "" prompt_text = ( f"Professional e-commerce model photography, {model_info['desc']} model " f"wearing {product}, {pose_desc}, {bg_desc}, " f"{model_info['outfit_hint']}, highlighting {feature_text}, " f"natural expression, {variation}, " f"high resolution, studio quality, no text, no watermark, no logo, " f"Amazon-compliant product photography" ) prompts.append({ "index": i + 1, "prompt": prompt_text.strip(), "model_type": model_type, "model_desc": model_info["desc"], "pose": pose, "background": background, "compliance_notes": [ "Model should appear confident but not overly posed", "Product must be clearly visible and identifiable", "No brand logos visible unless it's your own brand", "Avoid suggestive poses for Amazon compliance", ], }) ``` The command-line argument is accepted without an upper bound: ```python parser.add_argument("--count", type=int, default=3) ``` The JSON input path likewise passes an unvalidated value directly to `generate_prompts`: ```python args = parser.parse_args() params = json.loads(args.input) if args.input else None if params: result = generate_prompts( params.get("product", ""), params.get("category", ""), params.get("model_type", "lifestyle"), params.get("pose", "standing"), params.get("background", "studio_white"), params.get("count", 3), params.get("features", []), ) ``` ### Technical Analysis The application uses attacker-controlled `count` directly in `range(count)` and stores every generated entry in the ...[truncated 2160 chars]- Remediation
View remediation
int: if isinstance(value, bool) or not isinstance(value, int): raise ValueError("count must be an integer") if not 1 <= value <= MAX_PROMPT_COUNT: raise ValueError( f"count must be between 1 and {MAX_PROMPT_COUNT}" ) return value ``` Call the validator within `generate_prompts` so both command-line and JSON input paths are protected: ```python def generate_prompts(product: str, category: str, model_type: str, pose: str, background: str, count: int, features: list = None) -> dict: count = validate_count(count) # Continue with bounded prompt generation. ``` For command-line input, a bounded `argparse` type can provide earlier feedback: ```python def bounded_count(value: str) -> int: try: count = int(value) except ValueError as exc: raise argparse.ArgumentTypeError("count must be an integer") from exc if not 1 <= count <= MAX_PROMPT_COUNT: raise argparse.ArgumentTypeError( f"count must be between 1 and {MAX_PROMPT_COUNT}" ) return count parser.add_argument("--count", type=bounded_count, default=3) ``` ]]>
