T09 · Insecure Skill Coding Practices
- Location
scripts/generate_hn_daily.py:30- Finding
Unrestricted Article Retrieval Enables Server-Side Request Forgery and Local Resource Access
- Content
View full analysis
str: if not url: return "" try: req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"}) with urllib.request.urlopen(req, timeout=20) as r: raw = r.read(300_000).decode("utf-8", errors="ignore") except Exception: return "" raw = re.sub(r"", " ", raw, flags=re.I) raw = re.sub(r"", " ", raw, flags=re.I) txt = re.sub(r"<[^>]+>", " ", raw) txt = html.unescape(txt) txt = re.sub(r"\s+", " ", txt).strip() if len(txt) < 150: return "" return txt[:max_chars] ``` The externally controlled URL is passed to this function as follows: ```python for idx, st in enumerate(stories, 1): sid = st["id"] url = st.get("url") or f"https://news.ycombinator.com/item?id={sid}" snippet = fetch_article_snippet(url) comments_raw = collect_comments(st, limit=comments_limit) ``` ### Technical Analysis The article URL originates from Hacker News story metadata and is not trusted input. The code passes it directly to `urllib.request.urlopen` without validating: - The URL scheme. - The destination hostname or IP address. - The destination port. - Whether DNS resolution points to a private, loopback, link-local, reserved, or multicast address. - Redirect destinations. - Non-HTTP resource handlers supported by `urllib`. - Cloud instance metadata addresses. Consequently, a malicious or compromised Hacker News submission can cause the machine running the Skill to make requests from its own network context. Redirect handling can also bypass a su ...[truncated 1724 chars]- Remediation
View remediation
