T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/pdf_parser.py:56- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
bool: """判断输入是否为URL""" return path.startswith('http://') or path.startswith('https://') ``` ```python # 判断输入类型 if is_url(args.url): # URL输入:下载PDF temp_dir = "/tmp/pdf_downloads" os.makedirs(temp_dir, exist_ok=True) # 生成简短文件名(避免文件名过长问题) import hashlib url_hash = hashlib.md5(args.url.encode()).hexdigest()[:12] filename = f"report_{url_hash}.pdf" pdf_path = os.path.join(temp_dir, filename) pdf_path = download_pdf(args.url, pdf_path) ``` ### Technical Analysis The parser treats every string beginning with `http://` or `https://` as a valid remote PDF location and passes it directly to `requests.get()`. It does not validate the destination hostname, resolved IP address, port, or URL credentials. Consequently, the caller can direct the process to loopback, private, link-local, or otherwise restricted network destinations. Examples of potentially reachable targets include: - Loopback services such as `127.0.0.1` - RFC1918 private network services - Link-local cloud metadata services such as `169.254.169.254` - Internal services reachable only from the Agent's execution environment In addition, `requests` follows HTTP redirects by default. A URL initially resolving to a public address can therefore redirect the request to an internal destination unless every redirect target is separately validated. Although the response is expected to be a PDF, the implementation does not verify the response media type or file signature before saving and parsing it. Internal responses may consequently be written to disk and passed to ...[truncated 1532 chars]- Remediation
View remediation
