T09 · Insecure Skill Coding Practices
- Location
scripts/generate.py:24- Finding
Arbitrary Local File Disclosure Through Unvalidated Reference Image Path
- Content
View full analysis
dict: """Read an image file and return an OpenAI-style image_url content part.""" mime, _ = mimetypes.guess_type(path) if mime is None: mime = "image/png" with open(path, "rb") as f: b64 = base64.b64encode(f.read()).decode() return { "type": "image_url", "image_url": {"url": f"data:{mime};base64,{b64}"}, } def generate( prompt: str, output: str, ref_image: str | None = None, model: str = "google/gemini-3.1-flash-image-preview", api_key: str | None = None, base_url: str = "https://openrouter.ai/api/v1", ) -> str: """Generate an image and save to *output*. Returns the output path.""" api_key = api_key or os.environ.get("OPENROUTER_API_KEY") if not api_key: sys.exit("Error: OPENROUTER_API_KEY not set and --api-key not provided.") # Build message content content: list[dict] = [] if ref_image: content.append(encode_image(ref_image)) content.append({"type": "text", "text": prompt}) payload = { "model": model, "modalities": ["text", "image"], "messages": [{"role": "user", "content": content}], "max_tokens": 4096, } data = json.dumps(payload).encode() req = urllib.request.Request( f"{base_url}/chat/completions", data=data, headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", }, method="POST", ) ``` ### Technical Analysis The `--ref` argument is documented as a reference image, but `encode_image()` accepts any readable path. The implementation relies on the filename extension to infer a MIME type and defaults unknown files to `im ...[truncated 2203 chars]- Remediation
View remediation
