T09 · Insecure Skill Coding Practices
- Location
scripts/wechat_controller.py:300- Finding
Caller-Controlled Image URL Enables Blind SSRF and Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/wechat_controller.py:300-360
Vulnerability Type: Server-Side Request Forgery and unbounded remote-content processing
Risk Level: HighVulnerable Code
python def _download_image(self, url, max_retries=3): try: url_md5 = hashlib.md5(url.encode('utf-8')).hexdigest() cache_path = os.path.join(self.cache_dir, f"{url_md5}.png") if os.path.exists(cache_path): if os.path.getsize(cache_path) > 0: logger.info(f"Using cached image: {cache_path}") return cache_path else: os.remove(cache_path) logger.info(f"Starting image download: {url}") last_error = None for attempt in range(max_retries): try: response = requests.get(url, timeout=30, headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' }) response.raise_for_status() content_type = response.headers.get('content-type', '') if content_type and not content_type.startswith('image/'): if 'text/' in content_type or 'application/json' in content_type: return None image = Image.open(BytesIO(response.content)) image.verify() image = Image.open(BytesIO(response.content)) image.save(cache_path, 'PNG') return cache_path except requests.RequestException as e: last_error = e if attempt < max_retries - 1: time.sleep(1) continue except Exception as e: last_error = e break return None except Exception: return NoneThe displayed log messages have been translated into English for report readability; the executable beha ...[truncated 2870 chars]
- Remediation
View remediation
Remediation Suggestions
- Permit only explicitly supported schemes, preferably HTTPS.
- Parse the URL before use and reject embedded credentials, malformed hosts, and unexpected ports.
- Resolve the hostname and reject all loopback, private, link-local, multicast, reserved, unspecified, and metadata-service addresses for both IPv4 and IPv6.
- Revalidate the destination after DNS resolution and before each connection to reduce DNS rebinding exposure.
- Disable automatic redirects or validate every redirect destination using the same rules.
- Download with
stream=Trueand stop processing when a conservative byte limit is exceeded. - Validate
Content-Lengthwhen present, while retaining a streaming limit because that header is not trustworthy. - Configure Pillow decompression-bomb protections and enforce maximum image dimensions and pixel counts.
- Store successful cache files with restrictive permissions, enforce a total cache quota, and expire old files.
- Apply request-rate and queue-size limits to the API.
- If arbitrary remote images are not essential, accept only local files from an approved directory or require the caller to upload bounded image data directly.
