T09 · Insecure Skill Coding Practices
- Location
scripts/scrape.py:9- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
str: """Scrape a webpage and return content as markdown-like text.""" fetcher = Fetcher(auto_match=None) page = fetcher.fetch(url) ``` Related image-validation and download sinks: ```python def is_valid_image(url: str, min_size: int = 0) -> bool: """Check if URL points to a valid image (optionally by size).""" # Skip common small images (icons, avatars, etc.) skip_patterns = [ r'/avatar', r'/icon', r'/logo', r'/favicon', r'/emoji', r'/smiley', r'/button', r'/badge', r'/spinner', r'/loading', r'/blank\.', r'/pixel\.', r'/1x1', r'/spinner', ] for pattern in skip_patterns: if re.search(pattern, url, re.IGNORECASE): return False # Check file size if min_size specified if min_size > 0: try: resp = requests.head(url, timeout=10, allow_redirects=True) content_length = int(resp.headers.get('content-length', 0)) if content_length > 0 and content_length < min_size: return False except: pass return True ``` ```python def download_image(url: str, output_dir: Path, index: int) -> bool: """Download a single image.""" try: filename = get_filename(url, index) output_path = output_dir / filename # Skip if exists if output_path.exists(): print(f" Skip (exists): {filename}") return True print(f" Downloading: {url[:60]}...") response = requests.get(url, timeout=30) response.raise_for_status() with open(output_pa ...[truncated 2111 chars]- Remediation
View remediation
