T08 · Insecure Dependencies
Warning
- Location
- scripts/install_ocr_deps.sh:49
- Finding
- Unpinned Python Dependencies Installed with Root Privileges<![CDATA[ ## Vulnerability Details **File Location**: `scripts/install_ocr_deps.sh:9-14,49`; related mutable dependency declarations in `requirements.txt:4-9` **Vulnerability Type**: Unsafe privileged dependency installation **Risk Level**: Medium ### Vulnerable Code ```bash # scripts/install_ocr_deps.sh:10-14 if [ "$EUID" -ne 0 ]; then echo "⚠️ 请使用 sudo 运行此脚本" echo "用法:sudo ./install_ocr_deps.sh" exit 1 fi ``` ```bash # scripts/install_ocr_deps.sh:49 pip install pdf2image Pillow opencv-python-headless ``` ```text # requirements.txt:4-9 openpyxl>=3.0.0 pdfplumber>=0.7.0 pdf2image>=1.16.0 pytesseract>=0.3.10 Pillow>=9.0.0 opencv-python-headless>=4.5.0 ``` ### Technical Analysis The installation script refuses to run unless it has root privileges and subsequently invokes `pip` within that privileged process. The requested Python packages are not pinned to exact reviewed versions, and no package hashes or lock file are used. The dependency constraints in `requirements.txt` also allow any future version equal to or newer than the specified minimum. Python package installation may execute package build hooks and other installation-time code. Running this process as root means such code receives unrestricted system privileges. Because dependency resolution is mutable, the code ultimately installed can change after the Skill has been reviewed. Root access is reasonably necessary for the `yum` system-package operation, but it is not necessary for Python dependencies. Combining both operations in one root-only installer exceeds the minimum privileges required for the Skill's declared PDF and OCR functionality. ### Attack Path 1. A user follows the project documentation and executes `sudo ./scripts/install_ocr_deps.sh`. 2. The script verifies that it is running as root. 3. The unqualified `pip` command contacts its configured package index and resolves the latest packages satisfying the mutable constraints. 4. An attacker compromises a dependency release ...[truncated 1177 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Separate system-package installation from Python dependency installation. 2. Restrict the privileged section to the required system command, such as: ```bash sudo yum install -y tesseract tesseract-langpack-chi_simp tesseract-osd poppler-utils ``` 3. Create a dedicated non-root virtual environment for Python dependencies: ```bash python3 -m venv .venv .venv/bin/python -m pip install --require-hashes -r requirements.lock ``` 4. Pin every direct and transitive dependency to an exact reviewed version. 5. Generate and retain a lock file containing cryptographic hashes for all distributions. 6. Use `python3 -m pip` rather than an unqualified `pip` executable to prevent interpreter ambiguity. 7. Document the expected package index and reject untrusted or unexpected indexes. 8. Run dependency vulnerability and provenance checks during release preparation. 9. Remove the requirement that the entire installer run as root; fail if Python installation is attempted with effective UID zero. ]]>
