T08 · Insecure Dependencies
- Location
scripts/analyze_data.py:28- Finding
Unpinned Runtime Dependency Installation in Data Analyzer
- Content
View full analysis
Vulnerability Details
File Location:
scripts/analyze_data.py:28-47
Vulnerability Type: Unpinned runtime package installation
Risk Level: MediumVulnerable Code
python try: import pandas as pd import numpy as np from openpyxl import Workbook from openpyxl.styles import Font, PatternFill, Alignment, Border, Side from openpyxl.chart import BarChart, PieChart, Reference from openpyxl.utils import get_column_letter except ImportError: print("Required packages not found. Installing dependencies...") import subprocess subprocess.check_call([sys.executable, "-m", "pip", "install", "pandas", "openpyxl", "numpy", "-q"]) import pandas as pd import numpy as np from openpyxl import Workbook from openpyxl.styles import Font, PatternFill, Alignment, Border, Side from openpyxl.chart import BarChart, PieChart, Reference from openpyxl.utils import get_column_letterTechnical Analysis
If any dependency import fails, the script automatically invokes
pipand installspandas,openpyxl, andnumpy. No versions or package hashes are pinned, and the configured package index is trusted implicitly.This creates a supply-chain execution path because package installation and subsequent imports can execute package-controlled code. The installed versions may change over time, and the result depends on environment-level pip configuration such as index URLs, extra indexes, proxies, and trusted hosts. An
ImportErrorcaused by a partially broken installation may also unexpectedly trigger modification of the Python environment.Attack Path
- One of the required packages is absent or raises
ImportError. - The script enters the exception handler.
- The script invokes the environment's configured
pipclient without version or hash verification. - An attacker-controlled package index, compromised package release, dependenc ...[truncated 776 chars]
- One of the required packages is absent or raises
- Remediation
View remediation
Remediation Suggestions
- Remove automatic dependency installation from application runtime.
- If imports fail, terminate with a clear message directing the operator to an explicit setup procedure.
- Declare dependencies in a lock file or requirements file with exact versions.
- Require cryptographic hashes during installation, such as through
pip install --require-hashes. - Install dependencies in an isolated virtual environment during deployment rather than while processing user data.
- Restrict approved package indexes and avoid untrusted
--extra-index-urlconfigurations. - Run dependency vulnerability and provenance checks in CI before release.
