T09 · Insecure Skill Coding Practices
- Location
scripts/tt_download.py:149- Finding
Unrestricted URL Processing Enables SSRF and Cross-Host Cookie Forwarding
- Content
View full analysis
tuple[str, str, str]: """返回 (中间 cc.oceanengine.com src, 最终 video-cn 视频地址, cookie 字符串)。 注意:cc URL 在 302 时会下发 vck_xxx cookie,这个 cookie 是后续下载 video-cn 资源所必需的(缺它会返回 403 / X-Moat-Code 4119)。 """ html = render_with_chrome(page_url) cc_url = VideoSrcExtractor.extract_first(html) # cc.oceanengine.com URL 302 跳转到 video-cn 真实地址;不能跟随 body,只取 Location + Set-Cookie。 req = urllib.request.Request( cc_url, headers={ "User-Agent": UA, "Referer": "https://ad.oceanengine.com/", "Range": "bytes=0-1", # 只想要 redirect header,不下载内容 }, method="GET", ) opener = urllib.request.build_opener(NoRedirectHandler) try: opener.open(req, timeout=30) except urllib.error.HTTPError as e: location = e.headers.get("Location") if location: # 收集所有 Set-Cookie(可能多条) cookies = e.headers.get_all("Set-Cookie") or [] cookie_str = "; ".join( c.split(";", 1)[0].strip() for c in cookies if "=" in c ) return cc_url, location, cookie_str raise RuntimeError(f"cc URL 返回 HTTP {e.code} 但没有 Location 头。") raise RuntimeError("cc URL 未发生重定向,无法解析真实视频地址。") class NoRedirectHandler(urllib.request.HTTPRedirectHandler): """禁止 urllib 自动跟随 302/301,让我们能拿到 Location 头。""" def redirect_request(self, req, fp, code, msg, headers, newurl): return None def download(url: str, dest: str, cookie_str: str = "", chunk: int = 1 << 16) -> int: """把 url 流式写到 dest,返回写入字节数。""" headers = { "User-Agent": UA, "Referer": "https://ad.oceanengine.com/", } if cookie_str: headers["Cookie"] = ...[truncated 3955 chars]- Remediation
View remediation
