T08 · Insecure Dependencies
Warning
- Location
- scripts/generate_pdf.py:20
- Finding
- Automatic Installation of an Unpinned Runtime Dependency<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate_pdf.py:20-26` **Vulnerability Type**: Unsafe runtime dependency installation **Risk Level**: Medium ### Vulnerable Code ```python def install_if_missing(package: str, import_name=None): import_name = import_name or package try: __import__(import_name) except ImportError: print(f"正在安装依赖: {package} ...") subprocess.check_call([sys.executable, "-m", "pip", "install", package, "-q"]) ``` The function is invoked during Markdown conversion: ```python def md_to_html(md_text: str) -> str: install_if_missing("markdown") ``` ### Technical Analysis The PDF generator automatically invokes `pip` when the `markdown` module is unavailable. The package version is not pinned, no package hash is verified, and no lock file or isolated environment is used. Package resolution may also be affected by the invoking environment's pip configuration, configured indexes, or package mirrors. Python packages can execute code during installation. Consequently, the script treats mutable content retrieved from a package repository as trusted executable code. Automatic environment modification is not required for Markdown-to-PDF conversion and exceeds the minimum privileges necessary for the declared functionality. This is not direct evidence that the named `markdown` package is malicious. The vulnerability is the unsafe dependency acquisition mechanism and its exposure to repository compromise, malicious mirrors, configuration manipulation, and future upstream compromise. ### Attack Path 1. The Skill is invoked on a system where the `markdown` module is not installed or cannot be imported. 2. An attacker compromises or controls a package index, configured mirror, DNS/network path, or relevant pip configuration used by the environment. 3. The script executes `python -m pip install markdown -q` without enforcing a known version or artifact hash. 4. Pip downloads and installs ...[truncated 674 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove automatic package installation from the document-conversion path. 2. Declare dependencies in a version-controlled dependency file, such as `requirements.txt` or `pyproject.toml`. 3. Pin the exact approved package version and verify distribution hashes, for example with `pip install --require-hashes -r requirements.txt`. 4. Install dependencies during a controlled deployment or build phase rather than when processing a document. 5. Use a dedicated virtual environment or container with only the dependencies needed by the Skill. 6. Configure an explicitly trusted package index and prevent fallback to unapproved indexes. 7. If the dependency is unavailable at runtime, stop safely and provide installation instructions rather than modifying the environment automatically. 8. Periodically scan and update pinned dependencies through a reviewed change-management process. ]]>
