T09 · Insecure Skill Coding Practices
- Location
scripts/collect_images.py:122- Finding
Source Allowlist Bypass and Server-Side Request Forgery
- Content
View full analysis
Optional[Path]: try: for banned in BANNED_SOURCES: if banned in url: return None resp = self.session.get(url, timeout=15) if resp.status_code != 200: return None if not filename: url_hash = hashlib.md5(url.encode()).hexdigest()[:8] content_type = resp.headers.get("Content-Type", "image/jpeg") ext = content_type.split("/")[-1] if ext == "jpeg": ext = "jpg" filename = f"{url_hash}.{ext}" output_path = self.output_dir / filename output_path.write_bytes(resp.content) return output_path except Exception: return None ``` ### Technical Analysis The project claims that images are collected only from approved official sources, but `download_image()` does not enforce the `OFFICIAL_SOURCES` allowlist. It merely checks whether one of four banned strings appears anywhere in the URL. The code does not validate: - The URL scheme. - The normalized destination hostname. - Whether the hostname belongs to `OFFICIAL_SOURCES`. - Destination IP addresses after DNS resolution. - Redirect destinations. - Loopback, link-local, private, or reserved network ranges. - Embedded credentials or nonstandard ports. The `requests` library follows redirects by default. Consequently, even an initially approved URL could redirect the request to an unapproved or internal destination. The primary search implementation currently returns no candidates, which limits exposure through the normal CLI workflow. However, `download_image()` is a public method, and the validation flaw becomes exploitable if another ...[truncated 1295 chars]- Remediation
View remediation
