T09 · Insecure Skill Coding Practices
- Location
save_article_to_obsidian.py:302- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
str: """下载图片到本地""" try: url_hash = get_url_hash(img_url) ext = get_file_extension(img_url) filename = f"{article_hash}_{img_index:03d}_{url_hash}{ext}" subfolder = os.path.join(ATTACHMENTS_DIR, article_hash) os.makedirs(subfolder, exist_ok=True) filepath = os.path.join(subfolder, filename) if os.path.exists(filepath) and os.path.getsize(filepath) > 100: return f"../attachments/{article_hash}/{filename}" cmd = [ "curl", "-s", "-L", "--max-time", "30", "-H", "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)", "-H", "Referer: https://mp.weixin.qq.com/", "-o", filepath, img_url ] result = subprocess.run(cmd, capture_output=True, text=True) ``` ```python def fetch_with_retry(url: str, max_retries: int = 3) -> str: """带重试的抓取,针对不同站点使用不同策略""" last_error = None site_type = detect_site_type(url) wechat_ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.43" for attempt in range(max_retries): try: if attempt > 0: print(f" 🔄 第 {attempt + 1} 次尝试...") time.sleep(1) if site_type == 'wechat': cmd = [ "curl", "-s", "-L", "--max-time", "30", "-H", f"User-Agent: {wechat_ua}", "-H", "Accept: text/html,application/xhtml+xml", "-H", "Accept-Language: zh-CN", "-H", f"Referer: https://mp.weixin.qq.com/", ...[truncated 3478 chars]- Remediation
View remediation
