T08 · Insecure Dependencies
Warning
- Location
- scripts/read-file.py:55
- Finding
- Automatic Runtime Installation of Unpinned Third-Party Dependencies## Vulnerability Details **File Location**: `scripts/read-file.py:55-69` and `scripts/read-file.py:85-99` **Vulnerability Type**: Runtime installation of unpinned and unverified dependencies **Risk Level**: Medium ### Vulnerable Code `scripts/read-file.py:55-69`: ```python try: from docx import Document except ImportError: print(f"[自动安装] 检测到 python-docx 未安装,正在安装...", file=sys.stderr) import subprocess # 获取当前 Python 的 pip 路径 pip_cmd = [sys.executable, '-m', 'pip', 'install', 'python-docx', '-q'] try: subprocess.run(pip_cmd, check=True, capture_output=True) print(f"[自动安装] python-docx 安装成功", file=sys.stderr) from docx import Document except subprocess.CalledProcessError as e: raise ImportError( f"python-docx 安装失败:{e.stderr.decode('utf-8', errors='ignore') if e.stderr else str(e)}\n" f"请手动安装:{sys.executable} -m pip install python-docx" ) ``` `scripts/read-file.py:85-99`: ```python try: from pypdf import PdfReader except ImportError: print(f"[自动安装] 检测到 pypdf 未安装,正在安装...", file=sys.stderr) import subprocess # 获取当前 Python 的 pip 路径 pip_cmd = [sys.executable, '-m', 'pip', 'install', 'pypdf', '-q'] try: subprocess.run(pip_cmd, check=True, capture_output=True) print(f"[自动安装] pypdf 安装成功", file=sys.stderr) from pypdf import PdfReader except subprocess.CalledProcessError as e: raise ImportError( f"pypdf 安装失败:{e.stderr.decode('utf-8', errors='ignore') if e.stderr else str(e)}\n" f"请手动安装:{sys.executable} -m pip install pypdf" ) ``` ### Technical Analysis When a user opens a DOCX or PDF file and the corresponding parser is unavailable, the skill invokes pip automatically. The package names are not constrained to reviewed versions, and no package hashes or trusted repository URL ...[truncated 2066 chars]
- Remediation
- ## Remediation Suggestions 1. Remove automatic package installation from document-reading functions. If a parser is unavailable, fail safely and provide explicit setup instructions. 2. Install dependencies during a controlled build or deployment phase rather than while processing user-selected files. 3. Pin each dependency and relevant transitive dependencies to reviewed versions. 4. Require hashes, for example through a locked requirements file installed with `pip install --require-hashes`. 5. Configure pip to use an explicitly trusted package repository and prevent unreviewed alternate indexes. 6. Install dependencies inside a dedicated virtual environment or container instead of modifying the caller's global Python environment. 7. Run the skill under a least-privileged account with restricted filesystem and network access. 8. Add automated dependency vulnerability scanning and a controlled process for reviewing and updating pinned versions.
