T08 · Insecure Dependencies
- Location
scripts/generate_docs.py:14- Finding
Unpinned Third-Party Package Installation at Runtime
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_docs.py, lines 14–22
Vulnerability Type: Unpinned runtime dependency installation
Risk Level: Mediumpython try: from docx import Document from docx.shared import Inches, Pt, Cm from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.enum.table import WD_TABLE_ALIGNMENT except ImportError: print("Error: python-docx not installed. Installing...") os.system("pip install python-docx") from docx import Document from docx.shared import Inches, Pt, Cm from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.enum.table import WD_TABLE_ALIGNMENTTechnical Analysis
If any import in the
tryblock raisesImportError, the script automatically invokes a shell to installpython-docx. The dependency is not pinned to an audited version, verified with cryptographic hashes, or installed from a trusted, explicitly configured source. The installation also occurs without explicit user approval or environment isolation.Python package installation can execute package-controlled build and installation logic. Consequently, compromise of the package, one of its transitive dependencies, or the configured package index could result in attacker-controlled code execution. The broad
ImportErrorhandler may also initiate installation whenpython-docxis already present but an internal import fails for another reason.The command itself contains no user-controlled interpolation, so direct shell command injection is not established. The confirmed risk is unsafe supply-chain resolution and execution.
Attack Path
- An Agent or user executes
scripts/generate_docs.pyin an environment where one of the guarded imports raisesImportError. - The exception handler executes
pip install python-docxthroughos.system. - Pip resolves an unpinned package and its dependencies using the environment's configured index, mirrors, proxy, and trust settings.
- A ...[truncated 943 chars]
- An Agent or user executes
- Remediation
View remediation
Remediation Suggestions
- Remove automatic dependency installation from application runtime code. On a missing dependency, terminate with a clear error explaining the separate installation procedure.
- Declare
python-docxand all required transitive dependencies in a lockfile or requirements file using reviewed, exact versions. - Use cryptographic package hashes and enforce them during installation, such as with
pip install --require-hashes -r requirements.txt. - Perform dependency installation as an explicit setup step in an isolated virtual environment rather than modifying the Agent's global Python environment.
- Configure an approved HTTPS package index or internal artifact repository and disable untrusted extra indexes.
- Run dependency vulnerability and integrity checks as part of the release process.
- Catch only the specific missing-module condition if graceful handling is required; do not treat every
ImportErrorinside the import block as proof that installation is necessary. - Avoid shell invocation. Administrative setup tooling should use the active interpreter explicitly, for example
sys.executable -m pip, with a fixed argument list and only after user approval.
