T08 · Insecure Dependencies
Warning
- Location
- main.py:17
- Finding
- Unverified Download of a Mutable Font Asset## Vulnerability Details **File Location**: `main.py`, lines 17-39 **Vulnerability Type**: Unverified third-party component retrieval **Risk Level**: Medium ```python font_dir = "./fonts" font_name = "AlibabaPuHuiTi-3-65-Medium.ttf" font_path = os.path.join(font_dir, font_name) # 必须使用 raw.githubusercontent.com 获取真实二进制文件 raw_url = "https://raw.githubusercontent.com/cribug/universal-watermarker/main/fonts/AlibabaPuHuiTi-3-65-Medium.ttf" if not os.path.exists(font_path): print(f"⏳ 检测到首次运行,正在自动拉取核心字体: {font_name} ...") # 自动创建 fonts 文件夹 os.makedirs(font_dir, exist_ok=True) try: # 伪装 User-Agent,防止 GitHub API 拦截爬虫 req = urllib.request.Request( raw_url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'} ) with urllib.request.urlopen(req) as response, open(font_path, 'wb') as out_file: # 将流写入本地文件 out_file.write(response.read()) print("✅ 字体文件下载并部署成功!环境已就绪。") except Exception as e: print(f"❌ 字体下载失败,请检查网络或 URL: {e}") # 如果下载失败,抛出异常阻断后续运行,符合我们“宁可报错不可乱码”的原则 raise RuntimeError("初始化环境失败,无法获取字体文件。") ``` ### Technical Analysis On first execution, the Skill retrieves a TTF file from the mutable `main` branch of an external GitHub repository. Although HTTPS provides transport protection, the downloaded content is not pinned to an immutable commit and is not verified using a cryptographic digest or digital signature. No response-size limit or explicit font-format validation is applied before the response is written to disk. The downloaded file is subsequently parsed by Pillow and ReportLab during watermark generation. Fonts are complex binary inputs, and a malicious or malformed font could exercise vulnerabilities in those libraries or their underlying font-processing components. Bundling a reviewed font would eliminat ...[truncated 1479 chars]
- Remediation
- ## Remediation Suggestions 1. Bundle a reviewed and properly licensed font inside the Skill package so runtime network access is unnecessary. 2. If downloading remains necessary, reference an immutable repository commit rather than the mutable `main` branch. 3. Store the expected SHA-256 digest in source code and verify the complete download before moving it into the fonts directory. 4. Download into a securely created temporary file, validate its size and format, and atomically rename it only after successful verification. 5. Apply a strict response-size limit and reject redirects to unapproved hosts. 6. Delete partial or invalid files after any error. 7. Document the network requirement and destination domain clearly, and require explicit approval where the execution environment supports permission prompts.
