T08 · Insecure Dependencies
Error
- Location
- scripts/md2html.py:8
- Finding
- Unpinned Dependency Is Automatically Installed at Runtime<![CDATA[ ## Vulnerability Details **File Location**: `scripts/md2html.py`, lines 8–14 **Vulnerability Type**: Unsafe runtime dependency installation **Risk Level**: High ### Vulnerable Code ```python # 自动安装 markdown 库 try: import markdown except ImportError: import subprocess subprocess.check_call([sys.executable, "-m", "pip", "install", "markdown", "-q", "--break-system-packages"]) import markdown ``` ### Technical Analysis When the `markdown` module is unavailable, importing `md2html.py` automatically invokes pip and installs the latest package available under the name `markdown`. The dependency is not constrained by a version, cryptographic hash, lockfile, or explicitly trusted package index. Installation occurs during normal program execution rather than through a separate, user-approved setup process. The `--break-system-packages` option additionally permits pip to modify an externally managed Python environment, increasing the potential impact on the host. Python package installation and import can execute package-controlled code. Consequently, compromise of the configured package index, dependency account, package distribution, or local pip configuration could turn Markdown conversion into an arbitrary-code execution channel. ### Attack Path 1. The `markdown` module is absent from the active Python environment. 2. A user or Agent invokes `scripts/md2html.py` or imports it through `scripts/publish.py`. 3. The import handler executes `python -m pip install markdown -q --break-system-packages`. 4. Pip retrieves an unconstrained package version from its configured index. 5. Installation or subsequent import executes package-controlled code with the privileges of the invoking process. ### Impact Assessment Successful exploitation could execute arbitrary code with the Agent or user account's privileges. This may expose files, environment variables, WeChat credentials, cached access tokens, and other resources available to that accou ...[truncated 249 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove automatic dependency installation from module import and normal execution paths. 2. Declare a reviewed and pinned dependency in a dedicated requirements file, for example: ```text Markdown==<reviewed-version> --hash=sha256:<verified-hash> ``` 3. Install dependencies during an explicit setup phase with: ```bash python -m pip install --require-hashes -r requirements.txt ``` 4. Use an isolated virtual environment instead of `--break-system-packages`. 5. Configure an approved package index and disable unexpected fallback indexes. 6. Generate and retain a lockfile or software bill of materials for dependency review. 7. If the dependency is missing at runtime, terminate with a clear installation instruction rather than modifying the environment automatically. ]]>
