T09 · Insecure Skill Coding Practices
- Location
scripts/fetch.py:209- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
dict: """ 使用 BeautifulSoup 抓取网页内容(基础方案) 带重试机制和随机UA """ max_retries = 2 last_error = None for attempt in range(max_retries): try: headers = get_random_headers() # 创建会话 session = requests.Session() session.headers.update(headers) # 先访问建立cookies session.get(url, timeout=10, allow_redirects=True) time.sleep(0.5) # 正式请求 resp = session.get( url, timeout=15, headers=headers, allow_redirects=True ) ``` ### Technical Analysis The URL supplied to `fetch.py` is used directly in two HTTP requests without validating its scheme, hostname, resolved IP address, port, or redirect destinations. Redirect following is explicitly enabled. An attacker can therefore provide URLs targeting: - Loopback services such as `http://127.0.0.1:PORT/` - Private network services in RFC 1918 address ranges - Link-local services - Cloud instance metadata endpoints - IPv6 loopback or private addresses - Public URLs that redirect to internal destinations The initial request made to establish cookies and the subsequent request are both exposed. Checking only the original hostname would also be insufficient because redirects and DNS rebinding could change the effective destination. The browser-based Camoufox path elsewhere in the same file also navigates to an unrestricted URL, but the cited direct-request path is independently sufficient to establish the vulnerability. ### Attack Path 1. An attacker causes a crafted URL to b ...[truncated 1092 chars]- Remediation
View remediation
