T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/scrape_web.py:127
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/scrape_web.py`, lines 127–144 **Vulnerability Type**: Server-Side Request Forgery through an unrestricted user-controlled URL **Risk Level**: High ### Vulnerable Code ```python def fetch_page(url: str, timeout: int = 30) -> tuple: """Fetch page HTML and return (html_text, response).""" print(f"[FETCH] Fetching: {url}") try: resp = requests.get(url, headers=HEADERS, timeout=timeout, allow_redirects=True) resp.raise_for_status() # Detect encoding if resp.encoding and resp.encoding.lower() == "iso-8859-1": resp.encoding = resp.apparent_encoding html = resp.text print(f"[OK] Fetched {len(html)} bytes, encoding: {resp.encoding}") return html, resp except requests.exceptions.Timeout: print(f"[ERROR] Request timed out after {timeout}s") return "", None except requests.exceptions.HTTPError as e: print(f"[ERROR] HTTP error: {e}") return "", None except Exception as e: print(f"[ERROR] Fetch failed: {e}") return "", None ``` ### Technical Analysis The required `--url` argument is passed directly to `requests.get()` without validating its scheme, hostname, resolved IP address, or destination network. Redirects are explicitly enabled through `allow_redirects=True`, and redirect destinations are not revalidated. As a result, a user can make the host running the Skill send requests to network locations that may not be directly accessible to that user. Potential targets include: - Loopback services such as `127.0.0.1` and `::1` - Private IPv4 and IPv6 networks - Link-local services - Cloud instance metadata endpoints - Internal administration panels and APIs - Public URLs that redirect to an internal destination The scraper subsequently extracts response content and writes it to Markdown or JSON. The workflow may then expose that content to the agent or publish it to a We ...[truncated 1168 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Accept only explicitly supported `http` and `https` schemes. 2. Resolve the hostname before connecting and reject every address classified as loopback, private, link-local, multicast, unspecified, reserved, or otherwise non-global. 3. Disable automatic redirects and validate each redirect target before following it. 4. Repeat DNS and IP validation immediately before each connection to reduce DNS-rebinding risk. 5. Route scraping through an isolated outbound proxy that enforces destination restrictions. 6. Consider maintaining an allowlist of supported public domains where operationally practical. 7. Apply response-size and content-type limits to reduce denial-of-service exposure. 8. Keep the scraper in a sandbox without access to internal management networks or cloud metadata endpoints. ]]>
