T08 · Insecure Dependencies
Error
- Location
- scripts/generate_qr.py:9
- Finding
- Automatic Installation of an Unpinned Python Dependency## Vulnerability Details **File Location**: `scripts/generate_qr.py`, lines 9-17 **Vulnerability Type**: Unpinned runtime dependency installation **Risk Level**: High ### Vulnerable Code ```python def ensure_qrcode(): try: import qrcode return qrcode except ImportError: import subprocess subprocess.check_call([sys.executable, "-m", "pip", "install", "qrcode[pil]", "-q"]) import qrcode return qrcode ``` The automatic installation behavior is also explicitly documented in `SKILL.md`, lines 56-59: ```markdown ## Dependencies The script auto-installs `qrcode[pil]` via pip if missing. No manual setup needed. ``` ### Technical Analysis When the `qrcode` module is unavailable, the script invokes pip at runtime to install `qrcode[pil]`. The dependency has no pinned version, package hash, lockfile, or verified source repository. Pip therefore resolves a mutable package version using the environment's configured package indexes. This creates a supply-chain trust boundary during ordinary skill execution. If the package release, configured package index, DNS/network path, or local pip configuration is compromised, an attacker-controlled distribution could be installed. Python packages can execute code during installation or when imported immediately afterward. The subprocess call does not use a shell, so the package string itself does not create shell-command injection. The vulnerability is the uncontrolled acquisition and execution of mutable third-party code. ### Attack Path 1. An attacker compromises the relevant package distribution channel, a configured private package index, or the victim's pip configuration. 2. The skill runs in an environment where `qrcode` is not already installed. 3. `import qrcode` raises `ImportError`. 4. The exception handler invokes pip and resolves `qrcode[pil]` without a version or hash constraint. 5. The malicious o ...[truncated 710 chars]
- Remediation
- ## Remediation Suggestions 1. Remove automatic package installation from application runtime. If `qrcode` is unavailable, exit with a clear dependency error. 2. Declare the dependency in controlled project metadata such as `requirements.txt` or `pyproject.toml`. 3. Pin the package to a reviewed version and lock all transitive dependencies. 4. Use hash verification, such as pip's `--require-hashes`, for reproducible installations. 5. Install dependencies during a dedicated build or deployment phase rather than while processing user requests. 6. Restrict package indexes to explicitly trusted HTTPS repositories and disable unexpected fallback indexes. 7. Run the skill in a least-privileged, isolated environment without unnecessary credentials or filesystem access.
