T09 · Insecure Skill Coding Practices
- Location
- scripts/linkfox_os.py:803
- Finding
- Automatic Download of Unvalidated Server-Supplied URLs<![CDATA[ ## Vulnerability Details **File Location**: `scripts/linkfox_os.py:803-820` **Vulnerability Type**: Unvalidated remote resource retrieval **Risk Level**: Medium ### Vulnerable Code ```python def _download_resource_link(uri: str, name: str, output_dir: str) -> 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
- <![CDATA[ ## Remediation Suggestions 1. Accept only `https://` resource URLs. 2. Maintain an explicit allowlist of approved LinkFox and storage origins. 3. Resolve the destination hostname before connecting and reject loopback, private, link-local, multicast, and reserved IP ranges. 4. Repeat hostname and IP validation after every redirect, or disable redirects entirely. 5. Stream downloads in bounded chunks and enforce a documented maximum file size. 6. Enforce connection and read timeouts. 7. Validate content type and file extension against the expected resource type. 8. Generate local filenames independently instead of trusting URL-derived names. 9. Avoid overwriting existing files by using exclusive creation or randomized filenames. 10. Require user confirmation before downloading from an origin outside the normal LinkFox storage domains. ]]>
