T09 · Insecure Skill Coding Practices
- Location
scripts/pure_data_witness.py:108- Finding
SSRF Protection Can Be Bypassed Through DNS Resolution and Redirects
- Content
View full analysis
str | None: h = (host or "").lower().strip(".") if not h: return "empty_host" if h in BLOCK_HOSTS: return f"blocked_host:{h}" for suf in BLOCK_HOST_SUFFIXES: if h.endswith(suf) or h == suf.lstrip("."): return f"blocked_suffix:{suf}" # literal IP? try: ip = ipaddress.ip_address(h) if ( ip.is_private or ip.is_loopback or ip.is_link_local or ip.is_reserved or ip.is_multicast ): return f"blocked_ip_class:{ip}" except ValueError: pass return None ``` ```python def fetch_url(url: str, out_dir: Path, *, skip_content_gate: bool = False) -> dict: # Safety: scheme/host/SSRF before any request try: from pure_data_safety import check_url, check_content # type: ignore except ImportError: from pure_data_safety import check_url, check_content # type: ignore ugate = check_url(url) if not ugate.get("ok"): raise SystemExit(json.dumps({"error": "url_safety_reject", "gate": ugate}, indent=2)) req = urllib.request.Request(url, headers={"User-Agent": UA}) captured = utc_now() try: with urllib.request.urlopen(req, timeout=30) as resp: status = resp.status ctype = resp.headers.get("Content-Type", "application/octet-stream") data = resp.read(MAX_FETCH + 1) ``` ### Technical Analysis The URL gate rejects explicit private, loopback, link-local, reserved, and metadata IP addresses. However, it only applies `ipaddress.ip_address()` to the textual hostname supplied in the URL. For ordinary DNS hostnames, the code ...[truncated 2501 chars]- Remediation
View remediation
