T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/to_markdown.py:122- Finding
Insufficient URL Validation Enables Arbitrary Requests and Redirect-Based SSRF
- Content
View full analysis
str | None: """Download a URL to dest (no extension) and return final path, or None.""" try: req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) with urllib.request.urlopen(req, timeout=15) as resp: ct = resp.headers.get('Content-Type', 'image/png') ext = _ext_from_content_type(ct) final = dest + ext with open(final, 'wb') as f: f.write(resp.read()) return final except Exception: return None ``` ```python # ── Images already rendered as  ── img_pattern = re.compile(r'!\[([^\]]*)\]\((https://[^)]+feishu\.cn[^)]*)\)') img_jobs: list[tuple[str, str, str]] = [] # (original_url, dest_base, alt) seen_urls: dict[str, str] = {} for i, m in enumerate(img_pattern.finditer(markdown)): url = m.group(2) if url in seen_urls: continue dest_base = os.path.join(assets_dir, f'image-{i + 1}') seen_urls[url] = dest_base img_jobs.append((url, dest_base, m.group(1))) def _dl_img(job): url, dest_base, alt = job return url, download_image(url, dest_base) ``` ### Technical Analysis The code attempts to restrict image downloads to Feishu by checking whether the complete URL contains the string `feishu.cn`. This is not equivalent to validating the parsed network hostname. For example, both of the following attacker-controlled URLs satisfy the regular expression: ```text https://attacker.example/image?source=feishu.cn https://feishu.cn.attacker.example/image ``` The URL is passed directly to `urllib.request.urlopen`. This API follows HTTP redirects by default, and the code does not validate redirect destinations. Consequently, even ...[truncated 1502 chars]- Remediation
View remediation
