T09 · Insecure Skill Coding Practices
- Location
__init__.py:42- Finding
Server-Side Request Forgery Through Unrestricted URL Fetching
- Content
View full analysis
Dict[str, any]: """ 获取微信公众号文章的完整信息 Args: url: 微信公众号文章链接 (https://mp.weixin.qq.com/s/xxx) include_raw_html: 是否包含原始 HTML Returns: 包含文章信息的字典 Example: article = fetch_article("https://mp.weixin.qq.com/s/xxx") print(article['title']) print(article['content'][:200]) """ from bs4 import BeautifulSoup import requests # 下载网页 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', 'Referer': 'https://mp.weixin.qq.com/', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8' } response = requests.get(url, headers=headers, timeout=30) ``` The metadata API contains the same vulnerable request pattern: ```python def get_article_metadata(url: str) -> Dict[str, str]: """ 获取文章元数据(不包含正文) Args: url: 微信公众号文章链接 Returns: 包含标题、作者、发布时间等信息的字典 """ from bs4 import BeautifulSoup import requests headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'Referer': 'https://mp.weixin.qq.com/', } response = requests.get(url, headers=headers, timeout=30) ``` ### Technical Analysis The public APIs accept a caller-controlled `url` and pass it directly to `requests.get`. The implementation does not enforce the documented `mp.weixin.qq.com` destination, require HTTPS, restrict ports, resolve and inspect the destination IP address, or reject loopback, private, link-local, and reserved networks. Python Requests follows HTTP redirects by default. Consequently, even val ...[truncated 2142 chars]- Remediation
View remediation
