T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/convert.py:133
- Finding
- Response-Controlled Image URLs Enable Blind SSRF and Unbounded Downloads<![CDATA[ ## Vulnerability Details **File Location**: `scripts/convert.py:133-142` **Vulnerability Type**: Server-Side Request Forgery and uncontrolled resource download **Risk Level**: Medium ### Complete Code Snippet ```python target_path = images_dir / filename if str(image_data).startswith(("http://", "https://")): urllib.request.urlretrieve(str(image_data), target_path) else: target_path.write_bytes(decode_base64_image(str(image_data))) ``` ### Technical Analysis The `image_data` value comes from the remote OCR provider's response. When that value begins with `http://` or `https://`, the application downloads it with `urllib.request.urlretrieve()` without validating the destination host. The implementation does not: - Restrict downloads to documented PaddleOCR image hosts. - Reject loopback, private, link-local, multicast, or reserved IP addresses. - Revalidate the destination after DNS resolution. - Validate redirect targets. - Require HTTPS. - Apply an explicit download timeout. - Limit the number of downloaded bytes. - Verify that the response is an image before storing it. A malicious or compromised OCR endpoint can consequently direct the client to internal services such as `127.0.0.1`, RFC1918 network addresses, or cloud metadata endpoints. Redirects and DNS rebinding may also bypass superficial hostname checks unless every resolved and redirected destination is validated. Because the response is written to disk rather than returned to the OCR provider, the demonstrated issue is primarily blind SSRF rather than confirmed direct response exfiltration. Nevertheless, response timing, conversion success, generated archives, and locally accessible output files may reveal whether targeted resources exist. ### Attack Path 1. An attacker controls or compromises the OCR endpoint configured through `PADDLEOCR_DOC_PARSING_API_URL`. 2. The user submits a document for conversion. 3. Th ...[truncated 1337 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Prefer inline image data returned directly by the trusted OCR provider instead of retrieving secondary URLs. 2. If remote image downloads are required, maintain an explicit allowlist of documented provider hostnames. 3. Require HTTPS for non-local remote resources. 4. Resolve the hostname before connecting and reject loopback, private, link-local, multicast, unspecified, and reserved addresses for both IPv4 and IPv6. 5. Disable redirects or apply the same scheme, hostname, DNS, and IP validation to every redirect target. 6. Use a streaming HTTP client with explicit connection, read, and total timeouts. 7. Enforce a strict maximum response size and abort the transfer when the limit is exceeded. 8. Validate `Content-Type`, decode the image with a hardened image parser, and reject non-image content. 9. Limit the number and aggregate size of images accepted from each OCR response. 10. Document the secondary download behavior as part of the Skill's network and privacy boundary. ]]>
