T09 · Insecure Skill Coding Practices
- Location
data_parser.py:488- Finding
Unrestricted URL Retrieval Enables Server-Side Request Forgery
- Content
View full analysis
str: """从URL读取内容""" try: import urllib.request with urllib.request.urlopen(url, timeout=timeout) as response: return response.read().decode('utf-8', errors='ignore') except Exception as e: self.warnings.append(f'URL读取失败: {url}') self._stats['errors'] += 1 raise def parse_from_url(self, url: str, timeout: int = 30): """直接从URL解析""" content = self.read_from_url(url, timeout) if url.endswith('.csv'): import io return pd.read_csv(io.StringIO(content)) elif url.endswith('.json'): return json.loads(content) return content ``` ### Technical Analysis `parse_from_url()` accepts a caller-controlled URL and forwards it directly to `urllib.request.urlopen()` without validating: - The URL scheme - The destination hostname or port - The resolved IP address - Whether the destination is loopback, private, link-local, or otherwise reserved - Redirect destinations - The response content length Consequently, a caller can instruct the process to connect to internal services that are inaccessible from the caller's own network position. Depending on supported URL handlers and the runtime environment, non-HTTP resources may also be reachable. A timeout only restricts how long the request may block; it does not restrict where the request can go or how much response data may be read. ### Attack Path 1. An attacker supplies a crafted URL to a service or agent workflow that exposes `parse_from_url()` or `read_from_url()`. 2. The URL points to a sensitive internal destination, such as: - A loopback administrative service - A private network host - A link-local cloud metadata endpo ...[truncated 1060 chars]- Remediation
View remediation
