T09 · Insecure Skill Coding Practices
- Location
src/calorie_calculator.py:458- Finding
Arbitrary Local File Contents Can Be Transmitted to External Vision APIs
- Content
View full analysis
str: """Encode the image as Base64.""" with open(image_path, 'rb') as f: return base64.b64encode(f.read()).decode('utf-8') ``` The Kimi request reads the entire supplied file and represents it as a JPEG without validating its contents: ```python with open(image_path, 'rb') as f: base64_image = base64.b64encode(f.read()).decode('utf-8') payload = { "model": self.model, "messages": [ { "role": "user", "content": [ { "type": "text", "text": """Please identify the food in this image and return JSON.""" }, { "type": "image_url", "image_url": { "url": f"data:image/jpeg;base64,{base64_image}" } } ] } ], "max_tokens": 500 } response = requests.post( "https://api.moonshot.cn/v1/chat/completions", headers=headers, json=payload, timeout=30 ) ``` The OpenAI path repeats the same behavior: ```python with open(image_path, 'rb') as f: base64_image = base64.b64encode(f.read()).decode('utf-8') # ... "image_url": { "url": f"data:image/jpeg;base64,{base64_image}" } # ... response = requests.post( "https://api.openai.com/v1/chat/completions", headers=headers, json=payload, timeout=30 ) ``` The command-line entry point checks only whether the path exists: ```python image_path = sys.argv[1] if not os.path.exists(image_path): print(f"Error: image file does not exist: {image_path}") sys.exit(1) calculator = FoodCalo ...[truncated 2650 chars]- Remediation
View remediation
