T08 · Insecure Dependencies
- Location
generate-word-doc.py:8- Finding
Automatic Installation of an Unpinned Third-Party Dependency
- Content
View full analysis
Vulnerability Details
File Location:
generate-word-doc.py, lines 8-27
Vulnerability Type: Supply-chain exposure through automatic runtime dependency installation
Risk Level: HighComplete Code Snippet
python def install_package(package_name): """ 自动调用 pip 安装指定的库 """ print(f"⚠️ 检测到缺少库 '{package_name}',正在自动安装...") try: # 使用 sys.executable 确保安装到当前运行的 Python 环境中 subprocess.check_call([sys.executable, "-m", "pip", "install", package_name]) print(f"✅ 库 '{package_name}' 安装成功!") except subprocess.CalledProcessError: print(f"❌ 安装失败,请手动运行: pip install {package_name}") sys.exit(1) # 尝试导入 docx,如果失败则安装 try: import docx except ImportError: # 注意:pip 安装名是 'python-docx',但导入名是 'docx' install_package("python-docx") import docx # 安装后再次导入Technical Analysis
The module automatically invokes
pip install python-docxwhendocxcannot be imported. The dependency is identified only by its mutable package name; no exact version, artifact hash, trusted repository, or package-signature verification is enforced.Although the subprocess call uses an argument array and is not vulnerable to shell command injection, package installation inherently executes package build and installation logic. The effective package source also depends on the process's pip configuration, environment variables, configured indexes, and network environment. Consequently, a compromised package release, malicious transitive dependency, attacker-controlled package index, or manipulated pip configuration could introduce executable code after the skill has already been reviewed.
The installation occurs as an import-time side effect without explicit user confirmation. This expands a document-formatting operation into a network-facing software installation operation.
Attack Path
- The skill runs in an environment where the
docxmodu ...[truncated 1134 chars]
- The skill runs in an environment where the
- Remediation
View remediation
Remediation Suggestions
- Remove automatic dependency installation from module import and execution paths.
- Declare
python-docxin a reviewed dependency manifest or lock file using an exact approved version. - Require cryptographic hashes for downloaded artifacts, such as pip's
--require-hashesworkflow. - Install dependencies during a controlled build or deployment phase rather than while processing a document request.
- Restrict installation to a trusted package repository and prevent unreviewed user or environment configuration from changing the index.
- Run the skill inside a least-privileged virtual environment or container with limited filesystem, credential, and network access.
- If runtime installation is unavoidable, obtain explicit user approval and verify the exact version and artifact hash before installation.
