T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/pdf2.py:24
- Finding
- Unrestricted URL Navigation Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/pdf2.py`, lines 24–26 and 44–47 **Vulnerability Type**: Server-Side Request Forgery (SSRF) **Risk Level**: High ### Vulnerable Code ```python # Validate URL if not url.startswith(('http://', 'https://')): url = 'https://' + url ``` ```python browser = p.chromium.launch() page = browser.new_page() page.goto(url, wait_until='load', timeout=60000) ``` ### Technical Analysis The script accepts a user-controlled URL and passes it to Playwright without validating the destination hostname or resolved IP address. The check only ensures that the input begins with `http://` or `https://`, adding HTTPS otherwise. This does not prevent Chromium from connecting to loopback addresses, private network ranges, link-local addresses, cloud metadata services, or internal DNS names. Redirect targets are not validated either, so an initially public URL could redirect the browser to a protected internal resource. Because the resulting page is rendered into a PDF, content obtained from an internal endpoint may be returned to the requesting user through the generated document. ### Attack Path 1. An attacker supplies an address reachable from the host but not directly accessible to the attacker, such as `http://127.0.0.1:<port>`, an internal hostname, or a private-network address. 2. Alternatively, the attacker supplies a public URL that redirects to an internal destination. 3. The script accepts the URL because it uses an allowed scheme. 4. Playwright connects to the destination using the host's network access. 5. The internal response is rendered and written to the output PDF. 6. The attacker obtains the PDF and inspects information exposed by the internal service. ### Impact Assessment An attacker may access HTTP services reachable from the execution environment, including local administration interfaces, private intranet applications, development services, and potentially cloud instance metadata endpoints. ...[truncated 217 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Permit only explicitly required schemes, preferably HTTPS. - Parse the URL and reject embedded credentials, malformed hostnames, and unsupported ports. - Resolve the hostname before navigation and reject all loopback, private, link-local, multicast, unspecified, and reserved IPv4 and IPv6 addresses. - Revalidate the resolved address immediately before use to reduce DNS rebinding risk. - Validate every redirect destination using the same rules, or disable automatic redirects and process them manually. - Prefer an explicit domain allowlist when the intended use permits it. - Run Chromium in an isolated environment with outbound firewall rules that deny access to local, private, and metadata networks. - Apply request duration and response-size limits to reduce secondary denial-of-service risk. ]]>
