T09 · Insecure Skill Coding Practices
- Location
scripts/ocr_utils.py:63- Finding
Arbitrary URL Retrieval Enables Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ocr_utils.py, lines 63–72, 76–79, and 172–202
Vulnerability Type: Server-Side Request Forgery through unrestricted URL input
Risk Level: HighVulnerable Code
python def _download_image(url: str) -> str: """Download a network image to a temporary file and return its local path.""" import urllib.request suffix = os.path.splitext(url.split("?")[0])[1] or ".jpg" if suffix.lower() not in (".jpg", ".jpeg", ".png", ".webp", ".bmp"): suffix = ".jpg" fd, tmp_path = tempfile.mkstemp(suffix=suffix) os.close(fd) urllib.request.urlretrieve(url, tmp_path) # noqa: S310 return tmp_path def _detect_kind(path: str) -> str: """Determine the resource type from its extension.""" lower = path.lower() if lower.startswith("http://") or lower.startswith("https://"): return "url"python def extract_resume_text(source: str, max_pdf_pages: int = 3) -> str: ensure_dependencies() secret_id, secret_key = validate_env() kind = _detect_kind(source) local_path = source if kind == "url": print(f"[INFO] Downloading network image: {source}") local_path = _download_image(source) kind = _detect_kind(local_path) if kind == "pdf": text = _ocr_pdf(local_path, secret_id, secret_key, max_pages=max_pdf_pages) elif kind == "image": text = _general_accurate_ocr(local_path, secret_id, secret_key) else: raise RuntimeError(f"Unsupported resume file type: {source}") if local_path != source and os.path.exists(local_path): try: os.remove(local_path) except OSError: pass if not text.strip(): raise RuntimeError("OCR recognition result is empty.") return text.strip()Technical Analysis
The legacy OCR utility accepts any HTTP or HT ...[truncated 2117 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove URL input support because the documented main workflow accepts local resume files and does not require arbitrary remote retrieval.
- If remote input is necessary, require HTTPS and use a strict allowlist of approved domains.
- Resolve the hostname before connecting and reject loopback, private, link-local, multicast, unspecified, and reserved IP ranges for both IPv4 and IPv6.
- Repeat destination validation after every redirect and prevent HTTPS-to-HTTP downgrade.
- Use explicit connection and read timeouts.
- Stream responses while enforcing a strict byte limit rather than using unrestricted
urlretrieve. - Validate the response MIME type and verify the actual image format before OCR processing.
- Place temporary-file deletion in a
finallyblock so exceptions cannot leave downloaded data on disk. - Apply outbound network restrictions at the process or container level to block metadata and private-network destinations.
