T09 · Insecure Skill Coding Practices
- Location
scripts/linkfox_os.py:803- Finding
Automatic Download of Unvalidated Server-Supplied URLs
- Content
View full analysis
str: """将 resource_link 的 HTTPS URL 下载到 output_dir,返回本地路径。 若 uri 是 file:// 协议则跳过(无法远程下载)。失败时打印警告并返回空字符串。 """ if not uri or uri.startswith("file://"): return "" try: # 用 name 作为文件名兜底,从 URL 末尾取原始文件名 url_filename = uri.rstrip("/").split("/")[-1].split("?")[0] filename = url_filename or (name.replace(" ", "_") + ".bin") local_path = os.path.join(output_dir, filename) urlretrieve(uri, local_path) return local_path except Exception as e: print(f"Warning: 下载文件失败 [{name}] {uri}: {e}", file=sys.stderr) return "" ``` Server-provided URLs are passed to this function automatically from task event data: ```python uri = item.get("uri") or item.get("url") or "" name = item.get("name") or item.get("title") or "data" if uri and not uri.startswith("file://") and uri not in _seen_rl_uris: _seen_rl_uris.add(uri) task_dir = ensure_task_dir(msg_id) local = _download_resource_link(uri, name, task_dir) ``` ### Technical Analysis The implementation treats remote task results as trusted download instructions. It rejects only `file://` URLs and does not: - Require HTTPS. - Restrict downloads to approved LinkFox or S3 domains. - Reject loopback, private, link-local, or reserved destination addresses. - Validate the destination after redirects. - Limit the downloaded response size. - Validate the expected content type. - Stream the response with a strict byte limit. `urlretrieve()` follows the supplied URL and writes the complete response to disk. If an attacker can influence the LinkFox task result, compromise a configured API endpoint, or inject a malicious `resource_link`, the client can be induced to acces ...[truncated 1486 chars]- Remediation
View remediation
