T09 · Insecure Skill Coding Practices
- Location
scripts/hv_8_word.py:192- Finding
Optional Word Image Download Permits Server-Side Request Forgery
- Content
View full analysis
bytes | None: if requests is None: return None parsed = urlparse(str(url or "")) if parsed.scheme.lower() not in {"http", "https"} or not parsed.netloc: return None try: response = requests.get(str(url), timeout=(8, 20), allow_redirects=False, stream=True, headers={"User-Agent": "patsnap-high-value-screening/2.0"}) if response.status_code != 200 or "image/" not in response.headers.get("Content-Type", "").lower(): return None declared = response.headers.get("Content-Length") if declared and int(declared) > MAX_IMAGE_BYTES: return None content = bytearray() for block in response.iter_content(64 * 1024): content.extend(block) if len(content) > MAX_IMAGE_BYTES: return None return bytes(content) except (requests.RequestException, ValueError): return None ``` ### Technical Analysis The function accepts any URL whose scheme is HTTP or HTTPS and whose parsed URL contains a network location. It does not restrict the destination to PatSnap-controlled image hosts or reject loopback, private, link-local, multicast, reserved, and cloud metadata addresses. The drawing URL originates from the P021 API response in `scripts/hv_5_display.py` and is propagated through `final_records.json`. That checkpoint can also be modified locally before the optional Word generation stage. Consequently, either a compromised upstream response or a tampered checkpoint can control the destination requested by the process. Rejecting redirects reduces cross-host redirection risk but does not protect the initial request. The response size and content-type checks occur only after the ...[truncated 1415 chars]- Remediation
View remediation
