T08 · Insecure Dependencies
- Location
compress_pdf.py:153- Finding
Automatic Installation of an Unpinned Runtime Dependency
- Content
View full analysis
Vulnerability Details
File Location:
compress_pdf.py, lines 153-159
Vulnerability Type: Unpinned automatic third-party dependency installation
Risk Level: MediumVulnerable Code
python except ImportError: print(" pikepdf not installed, attempting to install...") subprocess.run( [sys.executable, "-m", "pip", "install", "pikepdf"], check=True, capture_output=True, ) import pikepdf return pikepdfTechnical Analysis
When
pikepdfis unavailable,_ensure_pikepdf()automatically invokes pip and installs the latest package version resolved under the user's current Python and package-index configuration. The dependency is not constrained by an exact version, lockfile, cryptographic hash, or verified artifact source.Although the subprocess call safely uses an argument list and does not expose a shell-command-injection issue, it introduces a supply-chain trust boundary during ordinary PDF processing. The code eventually imported is mutable and may differ from what was reviewed. Package installation can also execute package build or installation logic with the privileges of the running process.
The behavior is explicitly documented in
SKILL.md, so it is not concealed; nevertheless, documentation does not mitigate the dependency integrity risk.Attack Path
- A user runs the PDF compression tool in an environment where
pikepdfis not installed. - PDF processing calls
_ensure_pikepdf(). - The function executes
python -m pip install pikepdfwithout a version or hash constraint. - Pip resolves the package and transitive dependencies from the environment's configured index or mirror.
- If the upstream release, index, mirror, dependency chain, or local pip configuration is compromised, attacker-controlled package content is downloaded and installed.
- Malicious installation logic or imported package code executes under the identity and permissions of the user running the tool.
...[truncated 576 chars]
- A user runs the PDF compression tool in an environment where
- Remediation
View remediation
Remediation Suggestions
- Remove automatic package installation from runtime application logic. If
pikepdfis missing, terminate safely and display explicit installation instructions. - Declare dependencies in a version-controlled dependency manifest and pin
pikepdfand its transitive dependencies to reviewed versions. - Use a lockfile or a hash-validated requirements file, such as pip's
--require-hashes, to verify artifact integrity. - Install dependencies during a controlled deployment or setup phase rather than while processing user documents.
- Use an isolated virtual environment or container with least-privilege permissions.
- Restrict installation to a trusted package repository or approved internal mirror and validate its transport and access configuration.
- Require explicit user or administrator approval before any dependency installation.
- Add dependency vulnerability and provenance scanning to the release process.
A safer runtime pattern is:
python except ImportError as exc: raise RuntimeError( "pikepdf is required. Install the reviewed, pinned dependency " "in an isolated environment before running this tool." ) from exc- Remove automatic package installation from runtime application logic. If
